diff options
author | uint23 <[email protected]> | 2025-04-18 22:08:23 +0100 |
---|---|---|
committer | uint23 <[email protected]> | 2025-04-18 22:08:23 +0100 |
commit | b48471170819d6c23c3ef0eaaa3414c1dbf4908c (patch) | |
tree | e48e2615fe50f00ef4e7772b206f7c39498150b3 | |
parent | 75d7cd191653558f015a71ab33e3b68c889138f4 (diff) |
fixed snapping + config docs improved
-rw-r--r-- | src/defs.h | 12 | ||||
-rw-r--r-- | src/sxwm.c | 28 | ||||
-rw-r--r-- | src/usercfg.h | 92 |
3 files changed, 83 insertions, 49 deletions
@@ -13,18 +13,12 @@ #define SHIFT ShiftMask #define LENGTH(X) (sizeof X / sizeof X[0]) -#define BIND(mod, key, cmdstr) { (mod), XK_##key, { cmdstr }, 0 } +#define BIND(mod, key, cmdstr) { (mod), XK_##key, { cmdstr }, 0 } #define CALL(mod, key, fnptr) { (mod), XK_##key, { .fn = fnptr }, 1 } +#define CMD(name, ...) \ + static const char *name[] = { __VA_ARGS__, NULL } #define UDIST(a,b) abs((int)(a) - (int)(b)) -#define SNAP_EDGE(pos, size, bound) \ - do { \ - if (UDIST(pos, 0) < SNAP_DISTANCE) \ - pos = 0; \ - else if (UDIST(pos, (bound) - (size)) < SNAP_DISTANCE) \ - pos = (bound) - (size); \ - } while (0) - #define MAXCLIENTS 64 #define MAXGAPS 100 @@ -354,21 +354,41 @@ hdl_motion(XEvent *xev) int nx = drag_orig_x + dx; int ny = drag_orig_y + dy; +/* after computing nx = drag_orig_x + dx, ny = drag_orig_y + dy: */ + +/* after computing nx = drag_orig_x + dx, ny = drag_orig_y + dy: */ + if (drag_mode == DRAG_MOVE) { - SNAP_EDGE(nx, drag_client->w, scr_width); - SNAP_EDGE(ny, drag_client->h, scr_height); + int outerw = drag_client->w + 2 * BORDER_WIDTH; + int outerh = drag_client->h + 2 * BORDER_WIDTH; + + if (UDIST(nx, 0) <= SNAP_DISTANCE) { + nx = 0; + } else if (UDIST(nx + outerw, scr_width) <= SNAP_DISTANCE) { + nx = scr_width - outerw; + } + + // snap y + if (UDIST(ny, 0) <= SNAP_DISTANCE) { + ny = 0; + } else if (UDIST(ny + outerh, scr_height) <= SNAP_DISTANCE) { + ny = scr_height - outerh; + } if (!drag_client->floating && (UDIST(nx, drag_client->x) > SNAP_DISTANCE || - UDIST(ny, drag_client->y) > SNAP_DISTANCE)) + UDIST(ny, drag_client->y) > SNAP_DISTANCE)) { toggle_floating(); + } XMoveWindow(dpy, drag_client->win, nx, ny); drag_client->x = nx; drag_client->y = ny; } + + else { - // resize clamp is 20px + /* resize clamp is 20px */ int nw = drag_orig_w + dx; int nh = drag_orig_h + dy; drag_client->w = nw < 20 ? 20 : nw; diff --git a/src/usercfg.h b/src/usercfg.h index 8bf6b3a..44711b1 100644 --- a/src/usercfg.h +++ b/src/usercfg.h @@ -52,46 +52,25 @@ * ———————————< Keys & Bindins >————————————— * * * This is where you set your keybinds to - * open apps, kill apps, perform in-built - * functions. + * execute apps. You can use the CMD macro + * to make new variables. * - * How to make a command to run an app: + * How do you make a command to run an app + * It's simple! Just do this: * - * 1) Just write this: - * 'static const char *' - * you don't have to understand this, - * this is just how you make a string - * in C + * CALL(appcallname, "app", "arg2", ...); * - * 2) Call it what the app is called or - * anything you want really, eg. the - * command to open a terminal is - * termcmd. Also append a '[]' at the - * end to show its an array. This is - * for use of arguments eg 'ls -lah'. - * - * 3) Construct the command by putting '=' - * then after that open '{' then put - * the first arg in "arg0",. Repeat for - * all your args and end it with NULL. - * Strings in C are ended with a NULL - * 'terminator' which tells the program - * that that is the end of the string. - * - * 4) Finally, close the '}', then add - * a semi-colon at the end. - * - * After doing all that, you should have - * something like this: - * - * static const char *app = { "app", NULL }; + * What is appcallname? This is just the + * variable name given to this string of + * commands given to execvp, the function + * that executes these programs. * * ——————————— —————————————————————————————— * * */ -static const char *termcmd[] = { "st", NULL }; -static const char *browsercmd[] = { "firefox", NULL }; +CMD(terminal, "st"); +CMD(browser, "firefox"); /*< This is your modifier key (MOD/SUPER) >*/ #define MOD ALT @@ -102,13 +81,54 @@ static const char *browsercmd[] = { "firefox", NULL }; * This is where you assign keybinds to * perform some actions. * + * How do you bind keys? In sxwm, there is + * two ways to bind keys to perform tasks, + * BIND, or CALL. CALL, calls a function + * whereas BIND, executes a specified + * program. + * + * USEAGE: + * BIND(MODIFIERS, KEY, FUNCTION) + * + * MODIFIERS: + * The mod keys you want held down + * for the task to execute. I have + * also defined SHIFT as a substitute + * for ShiftMask. + * + * KEY: + * The key to press in combination + * with the MODIFERS to run the task. + * + * FUNCTION: + * The task to execute. Depending on + * whether you're calling CALL or + * BIND, this will execute a program + * or call a function. + * + * If you're + * calling a function, just put the + * name of the funtion. + * + * Otherwise, put the program you + * either defined with the CMD above + * or you can skip that step and just + * do something like this to create a + * "string" in the bindings array: + * + * { "program", "arg1", NULL } + * + * End the line with a comma, as this is + * an array. * * ——————————— —————————————————————————————— * */ static const Binding binds[] = { -/* Modifier(s) Key Function */ +/*——< MODIFIER(S) >——— < KEY >—————< FUNCTION >——*/ + +/*——— ——< Here are your functions calls > ———— — */ CALL(MOD|SHIFT, e, quit), CALL(MOD|SHIFT, q, close_focused), @@ -124,7 +144,7 @@ static const Binding binds[] = CALL(MOD, f, toggle_floating), CALL(MOD, space, toggle_floating_global), -/* Here are your executable functions */ - BIND(MOD, Return, termcmd), - BIND(MOD, b, browsercmd), +/*—————< Here are your executable functions >—————*/ + BIND(MOD, Return, terminal), + BIND(MOD, b, browser), }; |