From 96275a835d34b0e17da0c4d3bad294620f82d4d5 Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 27 Feb 2020 14:56:39 +0000 Subject: Unrelated style fixes, consistency changes and sorting, appropriate dosage/removal of wrappers, simplification of name queue, client cycle joins other kb/mb bound functions. --- calmwm.h | 77 +++++++++++++++++++++++++++++----------------------------------- 1 file changed, 35 insertions(+), 42 deletions(-) (limited to 'calmwm.h') diff --git a/calmwm.h b/calmwm.h index ac4cd3b..b15a39e 100644 --- a/calmwm.h +++ b/calmwm.h @@ -63,7 +63,6 @@ #define CWM_UP_LEFT (CWM_UP | CWM_LEFT) #define CWM_DOWN_RIGHT (CWM_DOWN | CWM_RIGHT) #define CWM_DOWN_LEFT (CWM_DOWN | CWM_LEFT) -#define DIRECTIONMASK (CWM_UP | CWM_DOWN | CWM_LEFT | CWM_RIGHT) #define CWM_CYCLE_FORWARD 0x0001 #define CWM_CYCLE_REVERSE 0x0002 @@ -100,11 +99,6 @@ struct geom { int w; int h; }; - -enum apply_gap { - CWM_NOGAP = 0, - CWM_GAP -}; struct gap { int top; int bottom; @@ -176,8 +170,9 @@ struct client_ctx { struct name_q nameq; char *name; char *label; - XClassHint ch; - XWMHints *wmh; + char *res_class; /* class hint */ + char *res_name; /* class hint */ + int initial_state; /* wm hint */ }; TAILQ_HEAD(client_q, client_ctx); @@ -390,40 +385,36 @@ extern Atom ewmh[EWMH_NITEMS]; extern struct screen_q Screenq; extern struct conf Conf; -__dead void usage(void); - -void client_applysizehints(struct client_ctx *); +void client_apply_sizehints(struct client_ctx *); +void client_close(struct client_ctx *); void client_config(struct client_ctx *); struct client_ctx *client_current(struct screen_ctx *); -void client_cycle(struct screen_ctx *, int); -void client_remove(struct client_ctx *); void client_draw_border(struct client_ctx *); struct client_ctx *client_find(Window); -long client_get_wm_state(struct client_ctx *); -void client_getsizehints(struct client_ctx *); +void client_get_sizehints(struct client_ctx *); void client_hide(struct client_ctx *); void client_htile(struct client_ctx *); +int client_inbound(struct client_ctx *, int, int); +struct client_ctx *client_init(Window, struct screen_ctx *, int); void client_lower(struct client_ctx *); -void client_msg(struct client_ctx *, Atom, Time); void client_move(struct client_ctx *); void client_mtf(struct client_ctx *); -int client_inbound(struct client_ctx *, int, int); -struct client_ctx *client_init(Window, struct screen_ctx *, int); +struct client_ctx *client_next(struct client_ctx *); +struct client_ctx *client_prev(struct client_ctx *); void client_ptr_inbound(struct client_ctx *, int); -void client_ptrsave(struct client_ctx *); -void client_ptrwarp(struct client_ctx *); +void client_ptr_save(struct client_ctx *); +void client_ptr_warp(struct client_ctx *); void client_raise(struct client_ctx *); +void client_remove(struct client_ctx *); void client_resize(struct client_ctx *, int); -void client_close(struct client_ctx *); -void client_set_wm_state(struct client_ctx *, long); -void client_setactive(struct client_ctx *); -void client_setname(struct client_ctx *); +void client_set_active(struct client_ctx *); +void client_set_name(struct client_ctx *); void client_show(struct client_ctx *); int client_snapcalc(int, int, int, int, int); -void client_toggle_freeze(struct client_ctx *); -void client_toggle_fullscreen(struct client_ctx *); void client_toggle_hidden(struct client_ctx *); void client_toggle_hmaximize(struct client_ctx *); +void client_toggle_fullscreen(struct client_ctx *); +void client_toggle_freeze(struct client_ctx *); void client_toggle_maximize(struct client_ctx *); void client_toggle_skip_pager(struct client_ctx *); void client_toggle_skip_taskbar(struct client_ctx *); @@ -453,16 +444,16 @@ void group_update_names(struct screen_ctx *); void search_match_client(struct menu_q *, struct menu_q *, char *); +void search_match_cmd(struct menu_q *, struct menu_q *, + char *); void search_match_exec(struct menu_q *, struct menu_q *, char *); +void search_match_group(struct menu_q *, struct menu_q *, + char *); void search_match_path(struct menu_q *, struct menu_q *, char *); void search_match_text(struct menu_q *, struct menu_q *, char *); -void search_match_cmd(struct menu_q *, struct menu_q *, - char *); -void search_match_group(struct menu_q *, struct menu_q *, - char *); void search_match_wm(struct menu_q *, struct menu_q *, char *); void search_print_client(struct menu *, int); @@ -472,19 +463,18 @@ void search_print_text(struct menu *, int); void search_print_wm(struct menu *, int); struct region_ctx *region_find(struct screen_ctx *, int, int); +void screen_assert_clients_within(struct screen_ctx *); +struct geom screen_area(struct screen_ctx *, int, int, int); struct screen_ctx *screen_find(Window); -struct geom screen_area(struct screen_ctx *, int, int, - enum apply_gap); void screen_init(int); -void screen_update_geometry(struct screen_ctx *); -void screen_updatestackingorder(struct screen_ctx *); -void screen_assert_clients_within(struct screen_ctx *); void screen_prop_win_create(struct screen_ctx *, Window); void screen_prop_win_destroy(struct screen_ctx *); void screen_prop_win_draw(struct screen_ctx *, const char *, ...) __attribute__((__format__ (printf, 2, 3))) __attribute__((__nonnull__ (2))); +void screen_update_geometry(struct screen_ctx *); +void screen_updatestackingorder(struct screen_ctx *); void kbfunc_cwm_status(void *, struct cargs *); void kbfunc_ptrmove(void *, struct cargs *); @@ -533,7 +523,6 @@ void menuq_clear(struct menu_q *); int parse_config(const char *, struct conf *); -void conf_atoms(void); void conf_autogroup(struct conf *, int, const char *, const char *); int conf_bind_key(struct conf *, const char *, @@ -556,12 +545,16 @@ void conf_group(struct screen_ctx *); void xev_process(void); -int xu_getprop(Window, Atom, Atom, long, unsigned char **); -int xu_getstrprop(Window, Atom, char **); -void xu_ptr_getpos(Window, int *, int *); -void xu_ptr_setpos(Window, int, int); +int xu_get_prop(Window, Atom, Atom, long, unsigned char **); +int xu_get_strprop(Window, Atom, char **); +void xu_ptr_get(Window, int *, int *); +void xu_ptr_set(Window, int, int); +void xu_get_wm_state(Window, long *); +void xu_set_wm_state(Window, long); +void xu_send_clientmsg(Window, Atom, Time); void xu_xorcolor(XftColor, XftColor, XftColor *); +void xu_atom_init(void); void xu_ewmh_net_supported(struct screen_ctx *); void xu_ewmh_net_supported_wm_check(struct screen_ctx *); void xu_ewmh_net_desktop_geometry(struct screen_ctx *); @@ -576,8 +569,8 @@ void xu_ewmh_net_showing_desktop(struct screen_ctx *); void xu_ewmh_net_virtual_roots(struct screen_ctx *); void xu_ewmh_net_current_desktop(struct screen_ctx *); void xu_ewmh_net_desktop_names(struct screen_ctx *); - -void xu_ewmh_net_wm_desktop(struct client_ctx *); +int xu_ewmh_get_net_wm_desktop(struct client_ctx *, long *); +void xu_ewmh_set_net_wm_desktop(struct client_ctx *); Atom *xu_ewmh_get_net_wm_state(struct client_ctx *, int *); void xu_ewmh_handle_net_wm_state_msg(struct client_ctx *, int, Atom , Atom); -- cgit 1.4.1 From 6c20772841684c18d85b45888de01e538f2999b4 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 24 Mar 2020 14:47:29 +0000 Subject: Instead of using _NET_ACTIVE_WINDOW on restart, use the pointer location to determine what client to set active. Reduces a round trip for every window. --- calmwm.h | 3 +-- client.c | 12 +----------- screen.c | 27 +++++++++++++++++---------- xevents.c | 2 +- xutil.c | 16 ---------------- 5 files changed, 20 insertions(+), 40 deletions(-) (limited to 'calmwm.h') diff --git a/calmwm.h b/calmwm.h index b15a39e..6fa5906 100644 --- a/calmwm.h +++ b/calmwm.h @@ -395,7 +395,7 @@ void client_get_sizehints(struct client_ctx *); void client_hide(struct client_ctx *); void client_htile(struct client_ctx *); int client_inbound(struct client_ctx *, int, int); -struct client_ctx *client_init(Window, struct screen_ctx *, int); +struct client_ctx *client_init(Window, struct screen_ctx *); void client_lower(struct client_ctx *); void client_move(struct client_ctx *); void client_mtf(struct client_ctx *); @@ -563,7 +563,6 @@ void xu_ewmh_net_workarea(struct screen_ctx *); void xu_ewmh_net_client_list(struct screen_ctx *); void xu_ewmh_net_client_list_stacking(struct screen_ctx *); void xu_ewmh_net_active_window(struct screen_ctx *, Window); -Window xu_ewmh_get_net_active_window(struct screen_ctx *); void xu_ewmh_net_number_of_desktops(struct screen_ctx *); void xu_ewmh_net_showing_desktop(struct screen_ctx *); void xu_ewmh_net_virtual_roots(struct screen_ctx *); diff --git a/client.c b/client.c index 21c51bc..61b2cf4 100644 --- a/client.c +++ b/client.c @@ -37,14 +37,11 @@ static void client_mwm_hints(struct client_ctx *); static void client_wm_protocols(struct client_ctx *); struct client_ctx * -client_init(Window win, struct screen_ctx *sc, int active) +client_init(Window win, struct screen_ctx *sc) { struct client_ctx *cc; XWindowAttributes wattr; int mapped; - Window rwin, cwin; - int x, y, wx, wy; - unsigned int mask; long state; if (win == None) @@ -108,10 +105,6 @@ client_init(Window win, struct screen_ctx *sc, int active) client_resize(cc, 0); if (cc->initial_state) xu_set_wm_state(cc->win, cc->initial_state); - } else { - if ((active == 0) && (XQueryPointer(X_Dpy, cc->win, &rwin, - &cwin, &x, &y, &wx, &wy, &mask)) && (cwin != None)) - active = 1; } XSelectInput(X_Dpy, cc->win, @@ -152,9 +145,6 @@ out: XSync(X_Dpy, False); XUngrabServer(X_Dpy); - if (active) - client_set_active(cc); - return cc; } diff --git a/screen.c b/screen.c index b1e70e9..373ff71 100644 --- a/screen.c +++ b/screen.c @@ -33,13 +33,12 @@ #include "calmwm.h" static struct geom screen_apply_gap(struct screen_ctx *, struct geom); -static void screen_scan(struct screen_ctx *, Window); +static void screen_scan(struct screen_ctx *); void screen_init(int which) { struct screen_ctx *sc; - Window active = None; XSetWindowAttributes attr; sc = xmalloc(sizeof(*sc)); @@ -67,7 +66,6 @@ screen_init(int which) xu_ewmh_net_number_of_desktops(sc); xu_ewmh_net_showing_desktop(sc); xu_ewmh_net_virtual_roots(sc); - active = xu_ewmh_get_net_active_window(sc); attr.cursor = Conf.cursor[CF_NORMAL]; attr.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | @@ -77,7 +75,7 @@ screen_init(int which) if (Conf.xrandr) XRRSelectInput(X_Dpy, sc->rootwin, RRScreenChangeNotifyMask); - screen_scan(sc, active); + screen_scan(sc); screen_updatestackingorder(sc); TAILQ_INSERT_TAIL(&Screenq, sc, entry); @@ -86,17 +84,26 @@ screen_init(int which) } static void -screen_scan(struct screen_ctx *sc, Window active) +screen_scan(struct screen_ctx *sc) { - Window *wins, w0, w1; - unsigned int nwins, i; + struct client_ctx *cc, *active = NULL; + Window *wins, w0, w1, rwin, cwin; + unsigned int nwins, i, mask; + int rx, ry, wx, wy; - if (XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins)) { - for (i = 0; i < nwins; i++) - (void)client_init(wins[i], sc, (active == wins[i])); + XQueryPointer(X_Dpy, sc->rootwin, &rwin, &cwin, + &rx, &ry, &wx, &wy, &mask); + if (XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins)) { + for (i = 0; i < nwins; i++) { + if ((cc = client_init(wins[i], sc)) != NULL) + if (cc->win == cwin) + active = cc; + } XFree(wins); } + if (active) + client_set_active(active); } struct screen_ctx * diff --git a/xevents.c b/xevents.c index 090886a..1aaa929 100644 --- a/xevents.c +++ b/xevents.c @@ -87,7 +87,7 @@ xev_handle_maprequest(XEvent *ee) client_ptr_save(old_cc); if ((cc = client_find(e->window)) == NULL) - cc = client_init(e->window, NULL, 0); + cc = client_init(e->window, NULL); if ((cc != NULL) && (!(cc->flags & CLIENT_IGNORE))) client_ptr_warp(cc); diff --git a/xutil.c b/xutil.c index 69da471..37af7db 100644 --- a/xutil.c +++ b/xutil.c @@ -296,22 +296,6 @@ xu_ewmh_net_active_window(struct screen_ctx *sc, Window w) XA_WINDOW, 32, PropModeReplace, (unsigned char *)&w, 1); } -Window -xu_ewmh_get_net_active_window(struct screen_ctx *sc) -{ - long *p; - Window win; - - if ((xu_get_prop(sc->rootwin, ewmh[_NET_ACTIVE_WINDOW], - XA_WINDOW, 32, (unsigned char **)&p)) <= 0) - return None; - - win = (Window)*p; - XFree(p); - - return win; -} - void xu_ewmh_net_number_of_desktops(struct screen_ctx *sc) { -- cgit 1.4.1 From 6407eb9bc1380d879f354c0331dbb5ea5302fe51 Mon Sep 17 00:00:00 2001 From: okan Date: Thu, 16 Apr 2020 13:32:35 +0000 Subject: Allow configuring a percentage window size of the master window during htile/vtile actions. From Uwe Werler, with a few manpage tweaks. --- calmwm.h | 2 ++ client.c | 6 ++++-- conf.c | 2 ++ cwmrc.5 | 22 ++++++++++++++++++++-- parse.y | 18 +++++++++++++++++- 5 files changed, 45 insertions(+), 5 deletions(-) (limited to 'calmwm.h') diff --git a/calmwm.h b/calmwm.h index 6fa5906..9ae2afe 100644 --- a/calmwm.h +++ b/calmwm.h @@ -291,6 +291,8 @@ struct conf { int bwidth; int mamount; int snapdist; + int htile; + int vtile; struct gap gap; char *color[CWM_COLOR_NITEMS]; char *font; diff --git a/client.c b/client.c index 61b2cf4..cfdd048 100644 --- a/client.c +++ b/client.c @@ -940,7 +940,8 @@ client_htile(struct client_ctx *cc) cc->geom.x = area.x; cc->geom.y = area.y; cc->geom.w = area.w - (cc->bwidth * 2); - cc->geom.h = (area.h - (cc->bwidth * 2)) / 2; + if (Conf.htile > 0) + cc->geom.h = ((area.h - (cc->bwidth * 2)) * Conf.htile) / 100; client_resize(cc, 1); client_ptr_warp(cc); @@ -1007,7 +1008,8 @@ client_vtile(struct client_ctx *cc) cc->flags &= ~CLIENT_VMAXIMIZED; cc->geom.x = area.x; cc->geom.y = area.y; - cc->geom.w = (area.w - (cc->bwidth * 2)) / 2; + if (Conf.vtile > 0) + cc->geom.w = ((area.w - (cc->bwidth * 2)) * Conf.vtile) / 100; cc->geom.h = area.h - (cc->bwidth * 2); client_resize(cc, 1); client_ptr_warp(cc); diff --git a/conf.c b/conf.c index bd06294..a3026cf 100644 --- a/conf.c +++ b/conf.c @@ -281,6 +281,8 @@ conf_init(struct conf *c) c->stickygroups = 0; c->bwidth = 1; c->mamount = 1; + c->htile = 50; + c->vtile = 50; c->snapdist = 0; c->ngroups = 0; c->nameqlen = 5; diff --git a/cwmrc.5 b/cwmrc.5 index fb07e2e..ab70d25 100644 --- a/cwmrc.5 +++ b/cwmrc.5 @@ -183,6 +183,13 @@ This can be used for applications such as .Xr xclock 1 , where the user may wish to remain visible. +.It Ic htile Ar percent +Set the percentage of screen the master window should occupy +after calling +.Ic window-htile . +If set to 0, the horizontal size of the master window will +remain unchanged. +The default is 50. .It Ic ignore Ar windowname Ignore, and do not warp to, windows with the name .Ar windowname @@ -216,6 +223,13 @@ A special keyword .Dq all can be used to unbind all buttons. +.It Ic vtile Ar percent +Set the percentage of screen the master window should occupy +after calling +.Ic window-vtile . +If set to 0, the vertical size of the master window will +remain unchanged. +The default is 50. .It Ic wm Ar name path Every .Ar name @@ -303,11 +317,15 @@ Vertically maximize current window (gap + border honored). Horizontally maximize current window (gap + border honored). .It window-htile Current window is placed at the top of the screen, maximized -horizontally and resized to half of the vertical screen space. +horizontally and resized to +.Ar htile +(default half) of the vertical screen space. Other windows in its group share remaining screen space. .It window-vtile Current window is placed on the left of the screen, maximized vertically -and resized to half of the horizontal screen space. +and resized to +.Ar vtile +(default half) of the horizontal screen space. Other windows in its group share remaining screen space. .It window-move Move current window. diff --git a/parse.y b/parse.y index 04e7bd4..0138fdb 100644 --- a/parse.y +++ b/parse.y @@ -71,7 +71,7 @@ typedef struct { %token BINDKEY UNBINDKEY BINDMOUSE UNBINDMOUSE %token FONTNAME STICKY GAP %token AUTOGROUP COMMAND IGNORE WM -%token YES NO BORDERWIDTH MOVEAMOUNT +%token YES NO BORDERWIDTH MOVEAMOUNT HTILE VTILE %token COLOR SNAPDIST %token ACTIVEBORDER INACTIVEBORDER URGENCYBORDER %token GROUPBORDER UNGROUPBORDER @@ -122,6 +122,20 @@ main : FONTNAME STRING { } conf->bwidth = $2; } + | HTILE NUMBER { + if ($2 < 0 || $2 > 99) { + yyerror("invalid htile percent"); + YYERROR; + } + conf->htile = $2; + } + | VTILE NUMBER { + if ($2 < 0 || $2 > 99) { + yyerror("invalid vtile percent"); + YYERROR; + } + conf->vtile = $2; + } | MOVEAMOUNT NUMBER { if ($2 < 0 || $2 > INT_MAX) { yyerror("invalid movemount"); @@ -316,6 +330,7 @@ lookup(char *s) { "fontname", FONTNAME}, { "gap", GAP}, { "groupborder", GROUPBORDER}, + { "htile", HTILE}, { "ignore", IGNORE}, { "inactiveborder", INACTIVEBORDER}, { "menubg", MENUBG}, @@ -329,6 +344,7 @@ lookup(char *s) { "unbind-mouse", UNBINDMOUSE}, { "ungroupborder", UNGROUPBORDER}, { "urgencyborder", URGENCYBORDER}, + { "vtile", VTILE}, { "wm", WM}, { "yes", YES} }; -- cgit 1.4.1