Compare commits

...

10 Commits

Author SHA1 Message Date
Ryan Goniwiecha
f1dd7ceb04 snap to half commands 2026-04-20 14:01:25 -04:00
Ryan Goniwiecha
9618137422 fix first mouse resize 2026-04-19 17:12:51 -04:00
Ryan Goniwiecha
00f6b03503 proper hover on raise 2026-04-19 16:45:28 -04:00
37090bd2ba add raise on hover 2026-04-19 16:19:55 -04:00
ba8e24c95a add scalefactor to cwmrc 2026-04-19 16:19:55 -04:00
okan
d7120f4eaa cvsimport
* refs/heads/master:
  handle Meta release as a separate mod key.
  add window-snap-center function
2026-01-05 14:46:59 +00:00
okan
fe0b4b28bd handle Meta release as a separate mod key.
from Sven M. Hallberg
2026-01-05 14:46:59 +00:00
job
d59960199b add window-snap-center function
OK tb@ okan@
2025-08-20 23:44:06 +00:00
okan
172b4dd0f8 cvsimport
* refs/heads/master:
  Grab the pointer against the root window instead of the client we're attempting to move and/or resize; prevents XNextEvent() from blocking on a client that might have been moved to a Withdrawn state.
2024-04-10 19:38:22 +00:00
okan
2a2d268cb0 Grab the pointer against the root window instead of the client we're attempting
to move and/or resize; prevents XNextEvent() from blocking on a client that
might have been moved to a Withdrawn state.

behavior noticed and reported by zenitds at proton.me - thanks!
2024-04-10 19:38:22 +00:00
8 changed files with 248 additions and 12 deletions

View File

@@ -116,7 +116,8 @@ main(int argc, char **argv)
pfd[0].events = POLLIN; pfd[0].events = POLLIN;
while (cwm_status == CWM_RUNNING) { while (cwm_status == CWM_RUNNING) {
xev_process(); xev_process();
if (poll(pfd, 1, -1) == -1) { xev_handle_timeout();
if (poll(pfd, 1, xev_pending_timeout()) == -1) {
if (errno != EINTR) if (errno != EINTR)
warn("poll"); warn("poll");
} }

View File

@@ -76,6 +76,7 @@ size_t strlcpy(char *, const char *, size_t);
#define CWM_LEFT 0x0004 #define CWM_LEFT 0x0004
#define CWM_RIGHT 0x0008 #define CWM_RIGHT 0x0008
#define CWM_BIGAMOUNT 0x0010 #define CWM_BIGAMOUNT 0x0010
#define CWM_CENTER 0x0020
#define CWM_UP_BIG (CWM_UP | CWM_BIGAMOUNT) #define CWM_UP_BIG (CWM_UP | CWM_BIGAMOUNT)
#define CWM_DOWN_BIG (CWM_DOWN | CWM_BIGAMOUNT) #define CWM_DOWN_BIG (CWM_DOWN | CWM_BIGAMOUNT)
#define CWM_LEFT_BIG (CWM_LEFT | CWM_BIGAMOUNT) #define CWM_LEFT_BIG (CWM_LEFT | CWM_BIGAMOUNT)
@@ -313,6 +314,9 @@ struct conf {
int nameqlen; int nameqlen;
int bwidth; int bwidth;
int mamount; int mamount;
int scalefactor;
int raiseonhover;
int raisedelay;
int snapdist; int snapdist;
int htile; int htile;
int vtile; int vtile;
@@ -515,6 +519,7 @@ void screen_updatestackingorder(struct screen_ctx *);
void kbfunc_cwm_status(void *, struct cargs *); void kbfunc_cwm_status(void *, struct cargs *);
void kbfunc_ptrmove(void *, struct cargs *); void kbfunc_ptrmove(void *, struct cargs *);
void kbfunc_client_snap(void *, struct cargs *); void kbfunc_client_snap(void *, struct cargs *);
void kbfunc_client_snaptohalf(void *, struct cargs *);
void kbfunc_client_move(void *, struct cargs *); void kbfunc_client_move(void *, struct cargs *);
void kbfunc_client_resize(void *, struct cargs *); void kbfunc_client_resize(void *, struct cargs *);
void kbfunc_client_close(void *, struct cargs *); void kbfunc_client_close(void *, struct cargs *);
@@ -581,6 +586,8 @@ void conf_screen(struct screen_ctx *);
void conf_group(struct screen_ctx *); void conf_group(struct screen_ctx *);
void xev_process(void); void xev_process(void);
int xev_pending_timeout(void);
void xev_handle_timeout(void);
int xu_get_prop(Window, Atom, Atom, long, unsigned char **); int xu_get_prop(Window, Atom, Atom, long, unsigned char **);
int xu_get_strprop(Window, Atom, char **); int xu_get_strprop(Window, Atom, char **);

View File

@@ -79,6 +79,8 @@ client_init(Window win, struct screen_ctx *sc)
cc->geom.y = wattr.y; cc->geom.y = wattr.y;
cc->geom.w = wattr.width; cc->geom.w = wattr.width;
cc->geom.h = wattr.height; cc->geom.h = wattr.height;
cc->savegeom = cc->geom;
cc->fullgeom = cc->geom;
cc->colormap = wattr.colormap; cc->colormap = wattr.colormap;
cc->obwidth = wattr.border_width; cc->obwidth = wattr.border_width;
cc->bwidth = Conf.bwidth; cc->bwidth = Conf.bwidth;

8
conf.c
View File

@@ -102,10 +102,15 @@ static const struct {
{ FUNC_CC(window-movetogroup-7, client_movetogroup, 7) }, { FUNC_CC(window-movetogroup-7, client_movetogroup, 7) },
{ FUNC_CC(window-movetogroup-8, client_movetogroup, 8) }, { FUNC_CC(window-movetogroup-8, client_movetogroup, 8) },
{ FUNC_CC(window-movetogroup-9, client_movetogroup, 9) }, { FUNC_CC(window-movetogroup-9, client_movetogroup, 9) },
{ FUNC_CC(window-snap-center, client_snap, (CWM_CENTER)) },
{ FUNC_CC(window-snap-up, client_snap, (CWM_UP)) }, { FUNC_CC(window-snap-up, client_snap, (CWM_UP)) },
{ FUNC_CC(window-snap-down, client_snap, (CWM_DOWN)) }, { FUNC_CC(window-snap-down, client_snap, (CWM_DOWN)) },
{ FUNC_CC(window-snap-right, client_snap, (CWM_RIGHT)) }, { FUNC_CC(window-snap-right, client_snap, (CWM_RIGHT)) },
{ FUNC_CC(window-snap-left, client_snap, (CWM_LEFT)) }, { FUNC_CC(window-snap-left, client_snap, (CWM_LEFT)) },
{ FUNC_CC(window-snap-up-half, client_snaptohalf, (CWM_UP)) },
{ FUNC_CC(window-snap-down-half, client_snaptohalf, (CWM_DOWN)) },
{ FUNC_CC(window-snap-right-half, client_snaptohalf, (CWM_RIGHT)) },
{ FUNC_CC(window-snap-left-half, client_snaptohalf, (CWM_LEFT)) },
{ FUNC_CC(window-snap-up-right, client_snap, (CWM_UP_RIGHT)) }, { FUNC_CC(window-snap-up-right, client_snap, (CWM_UP_RIGHT)) },
{ FUNC_CC(window-snap-up-left, client_snap, (CWM_UP_LEFT)) }, { FUNC_CC(window-snap-up-left, client_snap, (CWM_UP_LEFT)) },
{ FUNC_CC(window-snap-down-right, client_snap, (CWM_DOWN_RIGHT)) }, { FUNC_CC(window-snap-down-right, client_snap, (CWM_DOWN_RIGHT)) },
@@ -288,6 +293,9 @@ conf_init(struct conf *c)
c->stickygroups = 0; c->stickygroups = 0;
c->bwidth = 1; c->bwidth = 1;
c->mamount = 1; c->mamount = 1;
c->scalefactor = 10;
c->raiseonhover = 1;
c->raisedelay = 250;
c->htile = 50; c->htile = 50;
c->vtile = 50; c->vtile = 50;
c->snapdist = 0; c->snapdist = 0;

10
cwmrc.5
View File

@@ -401,6 +401,8 @@ pixels right.
Resize window 10 times Resize window 10 times
.Ar moveamount .Ar moveamount
pixels left. pixels left.
.It window-snap-center
Snap window to center.
.It window-snap-up .It window-snap-up
Snap window to top edge. Snap window to top edge.
.It window-snap-down .It window-snap-down
@@ -409,6 +411,14 @@ Snap window to bottom edge.
Snap window to right edge. Snap window to right edge.
.It window-snap-left .It window-snap-left
Snap window to left edge. Snap window to left edge.
.It window-snap-up-half
Snap and resize window to the top half of the screen.
.It window-snap-down-half
Snap and resize window to the bottom half of the screen.
.It window-snap-right-half
Snap and resize window to the right half of the screen.
.It window-snap-left-half
Snap and resize window to the left half of the screen.
.It window-snap-up-right .It window-snap-up-right
Snap window to top-right corner. Snap window to top-right corner.
.It window-snap-up-left .It window-snap-up-left

View File

@@ -47,6 +47,7 @@ static void kbfunc_client_move_kb(void *, struct cargs *);
static void kbfunc_client_move_mb(void *, struct cargs *); static void kbfunc_client_move_mb(void *, struct cargs *);
static void kbfunc_client_resize_kb(void *, struct cargs *); static void kbfunc_client_resize_kb(void *, struct cargs *);
static void kbfunc_client_resize_mb(void *, struct cargs *); static void kbfunc_client_resize_mb(void *, struct cargs *);
static Bool kbfunc_discard_configurerequest(Display *, XEvent *, XPointer);
void void
kbfunc_cwm_status(void *ctx, struct cargs *cargs) kbfunc_cwm_status(void *ctx, struct cargs *cargs)
@@ -54,10 +55,21 @@ kbfunc_cwm_status(void *ctx, struct cargs *cargs)
cwm_status = cargs->flag; cwm_status = cargs->flag;
} }
static Bool
kbfunc_discard_configurerequest(Display *dpy, XEvent *ev, XPointer arg)
{
Window *win = (Window *)arg;
(void)dpy;
return (ev->type == ConfigureRequest &&
ev->xconfigurerequest.window == *win);
}
static void static void
kbfunc_amount(int flags, int amt, int *mx, int *my) kbfunc_amount(int flags, int amt, int *mx, int *my)
{ {
#define CWM_FACTOR 10 #define CWM_FACTOR Conf.scalefactor
if (flags & CWM_BIGAMOUNT) if (flags & CWM_BIGAMOUNT)
amt *= CWM_FACTOR; amt *= CWM_FACTOR;
@@ -165,7 +177,7 @@ kbfunc_client_move_mb(void *ctx, struct cargs *cargs)
client_ptr_inbound(cc, 1); client_ptr_inbound(cc, 1);
if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK, if (XGrabPointer(X_Dpy, sc->rootwin, False, MOUSEMASK,
GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_MOVE], GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_MOVE],
CurrentTime) != GrabSuccess) CurrentTime) != GrabSuccess)
return; return;
@@ -242,6 +254,7 @@ kbfunc_client_resize_mb(void *ctx, struct cargs *cargs)
{ {
struct client_ctx *cc = ctx; struct client_ctx *cc = ctx;
XEvent ev; XEvent ev;
XEvent cev;
Time ltime = 0; Time ltime = 0;
struct screen_ctx *sc = cc->sc; struct screen_ctx *sc = cc->sc;
int resize = 1; int resize = 1;
@@ -254,7 +267,7 @@ kbfunc_client_resize_mb(void *ctx, struct cargs *cargs)
xu_ptr_set(cc->win, cc->geom.w, cc->geom.h); xu_ptr_set(cc->win, cc->geom.w, cc->geom.h);
if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK, if (XGrabPointer(X_Dpy, sc->rootwin, False, MOUSEMASK,
GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_RESIZE], GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_RESIZE],
CurrentTime) != GrabSuccess) CurrentTime) != GrabSuccess)
return; return;
@@ -270,8 +283,8 @@ kbfunc_client_resize_mb(void *ctx, struct cargs *cargs)
continue; continue;
ltime = ev.xmotion.time; ltime = ev.xmotion.time;
cc->geom.w = ev.xmotion.x; cc->geom.w = ev.xmotion.x - cc->geom.x - cc->bwidth;
cc->geom.h = ev.xmotion.y; cc->geom.h = ev.xmotion.y - cc->geom.y - cc->bwidth;
client_apply_sizehints(cc); client_apply_sizehints(cc);
client_resize(cc, 1); client_resize(cc, 1);
screen_prop_win_draw(sc, screen_prop_win_draw(sc,
@@ -282,8 +295,19 @@ kbfunc_client_resize_mb(void *ctx, struct cargs *cargs)
break; break;
} }
} }
if (ltime) if (ltime) {
/*
* A newly mapped client can queue a ConfigureRequest while the
* resize loop is consuming only mouse events. Drop those stale
* requests so the final drag geometry is not immediately
* overwritten when the main event loop resumes.
*/
while (XCheckIfEvent(X_Dpy, &cev,
kbfunc_discard_configurerequest,
(XPointer)&cc->win))
;
client_resize(cc, 1); client_resize(cc, 1);
}
screen_prop_win_destroy(sc); screen_prop_win_destroy(sc);
XUngrabPointer(X_Dpy, CurrentTime); XUngrabPointer(X_Dpy, CurrentTime);
@@ -323,11 +347,74 @@ kbfunc_client_snap(void *ctx, struct cargs *cargs)
(cc->bwidth * 2); (cc->bwidth * 2);
flags &= ~CWM_DOWN; flags &= ~CWM_DOWN;
} }
if (flags & CWM_CENTER) {
cc->geom.x = area.x +
(area.w - cc->geom.w - cc->bwidth) / 2;
cc->geom.y = area.y +
(area.h - cc->geom.h - cc->bwidth) / 2;
flags &= ~CWM_CENTER;
}
} }
client_move(cc); client_move(cc);
client_ptr_inbound(cc, 1); client_ptr_inbound(cc, 1);
} }
void
kbfunc_client_snaptohalf(void *ctx, struct cargs *cargs)
{
struct client_ctx *cc = ctx;
struct screen_ctx *sc = cc->sc;
struct geom area;
int halfw, halfh;
if (cc->flags & CLIENT_FREEZE)
return;
area = screen_area(sc,
cc->geom.x + cc->geom.w / 2,
cc->geom.y + cc->geom.h / 2, 1);
halfw = area.w / 2;
halfh = area.h / 2;
switch (cargs->flag) {
case CWM_UP:
cc->geom.x = area.x;
cc->geom.y = area.y;
cc->geom.w = area.w - (cc->bwidth * 2);
cc->geom.h = halfh - (cc->bwidth * 2);
client_apply_sizehints(cc);
break;
case CWM_DOWN:
cc->geom.x = area.x;
cc->geom.w = area.w - (cc->bwidth * 2);
cc->geom.h = area.h - halfh - (cc->bwidth * 2);
client_apply_sizehints(cc);
cc->geom.y = area.y + area.h - cc->geom.h -
(cc->bwidth * 2);
break;
case CWM_LEFT:
cc->geom.x = area.x;
cc->geom.y = area.y;
cc->geom.w = halfw - (cc->bwidth * 2);
cc->geom.h = area.h - (cc->bwidth * 2);
client_apply_sizehints(cc);
break;
case CWM_RIGHT:
cc->geom.y = area.y;
cc->geom.w = area.w - halfw - (cc->bwidth * 2);
cc->geom.h = area.h - (cc->bwidth * 2);
client_apply_sizehints(cc);
cc->geom.x = area.x + area.w - cc->geom.w -
(cc->bwidth * 2);
break;
default:
return;
}
client_resize(cc, 1);
client_ptr_inbound(cc, 1);
}
void void
kbfunc_client_close(void *ctx, struct cargs *cargs) kbfunc_client_close(void *ctx, struct cargs *cargs)
{ {

24
parse.y
View File

@@ -71,9 +71,9 @@ typedef struct {
%} %}
%token BINDKEY UNBINDKEY BINDMOUSE UNBINDMOUSE %token BINDKEY UNBINDKEY BINDMOUSE UNBINDMOUSE
%token FONTNAME STICKY GAP %token FONTNAME STICKY RAISEONHOVER RAISEONHOVERDELAY GAP
%token AUTOGROUP COMMAND IGNORE WM %token AUTOGROUP COMMAND IGNORE WM
%token YES NO BORDERWIDTH MOVEAMOUNT HTILE VTILE %token YES NO BORDERWIDTH MOVEAMOUNT SCALEFACTOR HTILE VTILE
%token COLOR SNAPDIST %token COLOR SNAPDIST
%token ACTIVEBORDER INACTIVEBORDER URGENCYBORDER %token ACTIVEBORDER INACTIVEBORDER URGENCYBORDER
%token GROUPBORDER UNGROUPBORDER %token GROUPBORDER UNGROUPBORDER
@@ -128,6 +128,16 @@ main : FONTNAME STRING {
| STICKY yesno { | STICKY yesno {
conf->stickygroups = $2; 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 { | BORDERWIDTH NUMBER {
if ($2 < 0 || $2 > INT_MAX) { if ($2 < 0 || $2 > INT_MAX) {
yyerror("invalid borderwidth"); yyerror("invalid borderwidth");
@@ -156,6 +166,13 @@ main : FONTNAME STRING {
} }
conf->mamount = $2; conf->mamount = $2;
} }
| SCALEFACTOR NUMBER {
if ($2 < 0 || $2 > INT_MAX) {
yyerror("invalid scalefactor");
YYERROR;
}
conf->scalefactor = $2;
}
| SNAPDIST NUMBER { | SNAPDIST NUMBER {
if ($2 < 0 || $2 > INT_MAX) { if ($2 < 0 || $2 > INT_MAX) {
yyerror("invalid snapdist"); yyerror("invalid snapdist");
@@ -350,6 +367,9 @@ lookup(char *s)
{ "menufg", MENUFG}, { "menufg", MENUFG},
{ "moveamount", MOVEAMOUNT}, { "moveamount", MOVEAMOUNT},
{ "no", NO}, { "no", NO},
{ "raise-delay", RAISEONHOVERDELAY},
{ "raise-on-hover", RAISEONHOVER},
{ "scalefactor", SCALEFACTOR},
{ "selfont", FONTSELCOLOR}, { "selfont", FONTSELCOLOR},
{ "snapdist", SNAPDIST}, { "snapdist", SNAPDIST},
{ "sticky", STICKY}, { "sticky", STICKY},

107
xevents.c
View File

@@ -33,7 +33,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <time.h>
#include "calmwm.h" #include "calmwm.h"
@@ -51,6 +51,12 @@ static void xev_handle_clientmessage(XEvent *);
static void xev_handle_randr(XEvent *); static void xev_handle_randr(XEvent *);
static void xev_handle_mappingnotify(XEvent *); static void xev_handle_mappingnotify(XEvent *);
static void xev_handle_expose(XEvent *); static void xev_handle_expose(XEvent *);
static void xev_cancel_hover_raise(void);
static void xev_schedule_hover_raise(Window);
static long long xev_now_ms(void);
static Window hover_raise_win = None;
static long long hover_raise_at = -1;
void (*xev_handlers[LASTEvent])(XEvent *) = { void (*xev_handlers[LASTEvent])(XEvent *) = {
[MapRequest] = xev_handle_maprequest, [MapRequest] = xev_handle_maprequest,
@@ -68,8 +74,84 @@ void (*xev_handlers[LASTEvent])(XEvent *) = {
[Expose] = xev_handle_expose, [Expose] = xev_handle_expose,
}; };
static KeySym modkeys[] = { XK_Alt_L, XK_Alt_R, XK_Super_L, XK_Super_R, static KeySym modkeys[] = { XK_Control_L, XK_Control_R,
XK_Control_L, XK_Control_R, XK_ISO_Level3_Shift }; XK_Alt_L, XK_Alt_R,
XK_Meta_L, XK_Meta_R,
XK_Super_L, XK_Super_R,
XK_ISO_Level3_Shift };
static long long
xev_now_ms(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ((long long)ts.tv_sec * 1000LL + ts.tv_nsec / 1000000LL);
}
static void
xev_cancel_hover_raise(void)
{
hover_raise_win = None;
hover_raise_at = -1;
}
static void
xev_schedule_hover_raise(Window win)
{
if (!Conf.raiseonhover || Conf.raisedelay < 0) {
xev_cancel_hover_raise();
return;
}
hover_raise_win = win;
hover_raise_at = xev_now_ms() + Conf.raisedelay;
}
int
xev_pending_timeout(void)
{
long long now, remaining;
if (hover_raise_win == None)
return (-1);
now = xev_now_ms();
remaining = hover_raise_at - now;
if (remaining <= 0)
return (0);
if (remaining > INT_MAX)
return (INT_MAX);
return ((int)remaining);
}
void
xev_handle_timeout(void)
{
struct client_ctx *cc;
Window win;
Window rwin, cwin;
int rx, ry, wx, wy;
unsigned int mask;
if (hover_raise_win == None || xev_now_ms() < hover_raise_at)
return;
win = hover_raise_win;
xev_cancel_hover_raise();
if ((cc = client_find(win)) == NULL || !(cc->flags & CLIENT_ACTIVE))
return;
if (!XQueryPointer(X_Dpy, cc->sc->rootwin, &rwin, &cwin,
&rx, &ry, &wx, &wy, &mask))
return;
if (cwin == cc->win) {
client_raise(cc);
XFlush(X_Dpy);
}
}
static void static void
xev_handle_maprequest(XEvent *ee) xev_handle_maprequest(XEvent *ee)
@@ -231,6 +313,21 @@ xev_handle_enternotify(XEvent *ee)
if ((cc = client_find(e->window)) != NULL) if ((cc = client_find(e->window)) != NULL)
client_set_active(cc); client_set_active(cc);
if (!Conf.raiseonhover)
return;
if (e->mode != NotifyNormal || e->detail == NotifyInferior)
return;
if (e->state & (Button1Mask | Button2Mask | Button3Mask |
Button4Mask | Button5Mask)) {
xev_cancel_hover_raise();
return;
}
if (cc != NULL)
xev_schedule_hover_raise(cc->win);
} }
static void static void
@@ -247,6 +344,8 @@ xev_handle_buttonpress(XEvent *ee)
if ((sc = screen_find(e->root)) == NULL) if ((sc = screen_find(e->root)) == NULL)
return; return;
xev_cancel_hover_raise();
e->state &= ~IGNOREMODMASK; e->state &= ~IGNOREMODMASK;
TAILQ_FOREACH(mb, &Conf.mousebindq, entry) { TAILQ_FOREACH(mb, &Conf.mousebindq, entry) {
@@ -489,5 +588,7 @@ xev_process(void)
xev_handle_randr(&e); xev_handle_randr(&e);
else if ((e.type < LASTEvent) && (xev_handlers[e.type] != NULL)) else if ((e.type < LASTEvent) && (xev_handlers[e.type] != NULL))
(*xev_handlers[e.type])(&e); (*xev_handlers[e.type])(&e);
xev_handle_timeout();
} }
xev_handle_timeout();
} }