Compare commits

..

2 Commits

Author SHA1 Message Date
22cd0f5f43 add raise on hover 2024-12-22 17:29:48 -05:00
ca083f97bd add scalefactor to cwmrc 2024-12-22 17:02:42 -05:00
7 changed files with 41 additions and 216 deletions

View File

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

View File

@@ -76,7 +76,6 @@ size_t strlcpy(char *, const char *, size_t);
#define CWM_LEFT 0x0004
#define CWM_RIGHT 0x0008
#define CWM_BIGAMOUNT 0x0010
#define CWM_CENTER 0x0020
#define CWM_UP_BIG (CWM_UP | CWM_BIGAMOUNT)
#define CWM_DOWN_BIG (CWM_DOWN | CWM_BIGAMOUNT)
#define CWM_LEFT_BIG (CWM_LEFT | CWM_BIGAMOUNT)
@@ -519,7 +518,6 @@ void screen_updatestackingorder(struct screen_ctx *);
void kbfunc_cwm_status(void *, struct cargs *);
void kbfunc_ptrmove(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_resize(void *, struct cargs *);
void kbfunc_client_close(void *, struct cargs *);
@@ -586,8 +584,6 @@ void conf_screen(struct screen_ctx *);
void conf_group(struct screen_ctx *);
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_strprop(Window, Atom, char **);

View File

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

5
conf.c
View File

@@ -102,15 +102,10 @@ static const struct {
{ FUNC_CC(window-movetogroup-7, client_movetogroup, 7) },
{ FUNC_CC(window-movetogroup-8, client_movetogroup, 8) },
{ 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-down, client_snap, (CWM_DOWN)) },
{ FUNC_CC(window-snap-right, client_snap, (CWM_RIGHT)) },
{ 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-left, client_snap, (CWM_UP_LEFT)) },
{ FUNC_CC(window-snap-down-right, client_snap, (CWM_DOWN_RIGHT)) },

10
cwmrc.5
View File

@@ -401,8 +401,6 @@ pixels right.
Resize window 10 times
.Ar moveamount
pixels left.
.It window-snap-center
Snap window to center.
.It window-snap-up
Snap window to top edge.
.It window-snap-down
@@ -411,14 +409,6 @@ Snap window to bottom edge.
Snap window to right edge.
.It window-snap-left
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
Snap window to top-right corner.
.It window-snap-up-left

View File

@@ -47,7 +47,6 @@ static void kbfunc_client_move_kb(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_mb(void *, struct cargs *);
static Bool kbfunc_discard_configurerequest(Display *, XEvent *, XPointer);
void
kbfunc_cwm_status(void *ctx, struct cargs *cargs)
@@ -55,17 +54,6 @@ kbfunc_cwm_status(void *ctx, struct cargs *cargs)
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
kbfunc_amount(int flags, int amt, int *mx, int *my)
{
@@ -177,7 +165,7 @@ kbfunc_client_move_mb(void *ctx, struct cargs *cargs)
client_ptr_inbound(cc, 1);
if (XGrabPointer(X_Dpy, sc->rootwin, False, MOUSEMASK,
if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_MOVE],
CurrentTime) != GrabSuccess)
return;
@@ -254,7 +242,6 @@ kbfunc_client_resize_mb(void *ctx, struct cargs *cargs)
{
struct client_ctx *cc = ctx;
XEvent ev;
XEvent cev;
Time ltime = 0;
struct screen_ctx *sc = cc->sc;
int resize = 1;
@@ -267,7 +254,7 @@ kbfunc_client_resize_mb(void *ctx, struct cargs *cargs)
xu_ptr_set(cc->win, cc->geom.w, cc->geom.h);
if (XGrabPointer(X_Dpy, sc->rootwin, False, MOUSEMASK,
if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_RESIZE],
CurrentTime) != GrabSuccess)
return;
@@ -283,8 +270,8 @@ kbfunc_client_resize_mb(void *ctx, struct cargs *cargs)
continue;
ltime = ev.xmotion.time;
cc->geom.w = ev.xmotion.x - cc->geom.x - cc->bwidth;
cc->geom.h = ev.xmotion.y - cc->geom.y - cc->bwidth;
cc->geom.w = ev.xmotion.x;
cc->geom.h = ev.xmotion.y;
client_apply_sizehints(cc);
client_resize(cc, 1);
screen_prop_win_draw(sc,
@@ -295,19 +282,8 @@ kbfunc_client_resize_mb(void *ctx, struct cargs *cargs)
break;
}
}
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))
;
if (ltime)
client_resize(cc, 1);
}
screen_prop_win_destroy(sc);
XUngrabPointer(X_Dpy, CurrentTime);
@@ -347,74 +323,11 @@ kbfunc_client_snap(void *ctx, struct cargs *cargs)
(cc->bwidth * 2);
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_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
kbfunc_client_close(void *ctx, struct cargs *cargs)
{

136
xevents.c
View File

@@ -30,10 +30,11 @@
#include <err.h>
#include <errno.h>
#include <limits.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "calmwm.h"
@@ -51,12 +52,6 @@ static void xev_handle_clientmessage(XEvent *);
static void xev_handle_randr(XEvent *);
static void xev_handle_mappingnotify(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 *) = {
[MapRequest] = xev_handle_maprequest,
@@ -74,84 +69,8 @@ void (*xev_handlers[LASTEvent])(XEvent *) = {
[Expose] = xev_handle_expose,
};
static KeySym modkeys[] = { XK_Control_L, XK_Control_R,
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 KeySym modkeys[] = { XK_Alt_L, XK_Alt_R, XK_Super_L, XK_Super_R,
XK_Control_L, XK_Control_R, XK_ISO_Level3_Shift };
static void
xev_handle_maprequest(XEvent *ee)
@@ -301,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)
{
@@ -314,20 +258,14 @@ xev_handle_enternotify(XEvent *ee)
if ((cc = client_find(e->window)) != NULL)
client_set_active(cc);
if (!Conf.raiseonhover)
return;
if (Conf.raiseonhover) {
Window *w;
w = (Window*)malloc(sizeof(Window));
memcpy(w, &e->window, sizeof(Window));
if (e->mode != NotifyNormal || e->detail == NotifyInferior)
return;
if (e->state & (Button1Mask | Button2Mask | Button3Mask |
Button4Mask | Button5Mask)) {
xev_cancel_hover_raise();
return;
pthread_t thread_id;
pthread_create(&thread_id, NULL, delay_raise, w);
}
if (cc != NULL)
xev_schedule_hover_raise(cc->win);
}
static void
@@ -344,8 +282,6 @@ xev_handle_buttonpress(XEvent *ee)
if ((sc = screen_find(e->root)) == NULL)
return;
xev_cancel_hover_raise();
e->state &= ~IGNOREMODMASK;
TAILQ_FOREACH(mb, &Conf.mousebindq, entry) {
@@ -588,7 +524,5 @@ xev_process(void)
xev_handle_randr(&e);
else if ((e.type < LASTEvent) && (xev_handlers[e.type] != NULL))
(*xev_handlers[e.type])(&e);
xev_handle_timeout();
}
xev_handle_timeout();
}