From 5cbfac0aaeac4bca9a05a0253b38215d6002442d Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 22 Dec 2024 17:28:57 -0500 Subject: [PATCH] add raise on hover --- calmwm.h | 2 ++ conf.c | 2 ++ parse.y | 14 +++++++++++++- xevents.c | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/calmwm.h b/calmwm.h index d6779f7..f261097 100644 --- a/calmwm.h +++ b/calmwm.h @@ -314,6 +314,8 @@ struct conf { int bwidth; int mamount; int scalefactor; + int raiseonhover; + int raisedelay; int snapdist; int htile; int vtile; diff --git a/conf.c b/conf.c index 2db89a9..a957984 100644 --- a/conf.c +++ b/conf.c @@ -289,6 +289,8 @@ conf_init(struct conf *c) c->bwidth = 1; c->mamount = 1; c->scalefactor = 10; + c->raiseonhover = 1; + c->raisedelay = 250; c->htile = 50; c->vtile = 50; c->snapdist = 0; diff --git a/parse.y b/parse.y index 45aee3d..188ba96 100644 --- a/parse.y +++ b/parse.y @@ -71,7 +71,7 @@ typedef struct { %} %token BINDKEY UNBINDKEY BINDMOUSE UNBINDMOUSE -%token FONTNAME STICKY GAP +%token FONTNAME STICKY RAISEONHOVER RAISEONHOVERDELAY GAP %token AUTOGROUP COMMAND IGNORE WM %token YES NO BORDERWIDTH MOVEAMOUNT SCALEFACTOR HTILE VTILE %token COLOR SNAPDIST @@ -128,6 +128,16 @@ main : FONTNAME STRING { | STICKY yesno { conf->stickygroups = $2; } + | RAISEONHOVER yesno { + conf->raiseonhover = $2; + } + | RAISEONHOVERDELAY NUMBER { + if ($2 < 0 || $2 > INT_MAX) { + yyerror("invalid delay"); + YYERROR; + } + conf->raisedelay = $2; + } | BORDERWIDTH NUMBER { if ($2 < 0 || $2 > INT_MAX) { yyerror("invalid borderwidth"); @@ -357,6 +367,8 @@ lookup(char *s) { "menufg", MENUFG}, { "moveamount", MOVEAMOUNT}, { "no", NO}, + { "raise-delay", RAISEONHOVERDELAY}, + { "raise-on-hover", RAISEONHOVER}, { "scalefactor", SCALEFACTOR}, { "selfont", FONTSELCOLOR}, { "snapdist", SNAPDIST}, diff --git a/xevents.c b/xevents.c index 5e138aa..cdeb916 100644 --- a/xevents.c +++ b/xevents.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -219,6 +220,31 @@ xev_handle_propertynotify(XEvent *ee) } } +static void* +delay_raise(void* data) +{ + struct client_ctx *cc; + Window *w = (Window*)data; + + int delay = Conf.raisedelay * 1000; + usleep(delay); + if ((cc = client_find(*w)) != NULL) { + if (cc->flags & CLIENT_ACTIVE) { + client_raise(cc); + } + } + free(w); + + XEvent e; + + XNextEvent(X_Dpy, &e); + if ((e.type - Conf.xrandr_event_base) == RRScreenChangeNotify) + xev_handle_randr(&e); + else if ((e.type < LASTEvent) && (xev_handlers[e.type] != NULL)) + (*xev_handlers[e.type])(&e); + pthread_exit(NULL); +} + static void xev_handle_enternotify(XEvent *ee) { @@ -231,6 +257,15 @@ xev_handle_enternotify(XEvent *ee) if ((cc = client_find(e->window)) != NULL) client_set_active(cc); + + if (Conf.raiseonhover) { + Window *w; + w = (Window*)malloc(sizeof(Window)); + memcpy(w, &e->window, sizeof(Window)); + + pthread_t thread_id; + pthread_create(&thread_id, NULL, delay_raise, w); + } } static void