Compare commits
10 Commits
22cd0f5f43
...
linux
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1dd7ceb04 | ||
|
|
9618137422 | ||
|
|
00f6b03503 | ||
| 37090bd2ba | |||
| ba8e24c95a | |||
|
|
d7120f4eaa | ||
|
|
fe0b4b28bd | ||
|
|
d59960199b | ||
|
|
172b4dd0f8 | ||
|
|
2a2d268cb0 |
3
calmwm.c
3
calmwm.c
@@ -116,7 +116,8 @@ main(int argc, char **argv)
|
||||
pfd[0].events = POLLIN;
|
||||
while (cwm_status == CWM_RUNNING) {
|
||||
xev_process();
|
||||
if (poll(pfd, 1, -1) == -1) {
|
||||
xev_handle_timeout();
|
||||
if (poll(pfd, 1, xev_pending_timeout()) == -1) {
|
||||
if (errno != EINTR)
|
||||
warn("poll");
|
||||
}
|
||||
|
||||
7
calmwm.h
7
calmwm.h
@@ -76,6 +76,7 @@ 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)
|
||||
@@ -313,6 +314,9 @@ struct conf {
|
||||
int nameqlen;
|
||||
int bwidth;
|
||||
int mamount;
|
||||
int scalefactor;
|
||||
int raiseonhover;
|
||||
int raisedelay;
|
||||
int snapdist;
|
||||
int htile;
|
||||
int vtile;
|
||||
@@ -515,6 +519,7 @@ 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 *);
|
||||
@@ -581,6 +586,8 @@ 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 **);
|
||||
|
||||
2
client.c
2
client.c
@@ -79,6 +79,8 @@ 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;
|
||||
|
||||
8
conf.c
8
conf.c
@@ -102,10 +102,15 @@ 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)) },
|
||||
@@ -288,6 +293,9 @@ conf_init(struct conf *c)
|
||||
c->stickygroups = 0;
|
||||
c->bwidth = 1;
|
||||
c->mamount = 1;
|
||||
c->scalefactor = 10;
|
||||
c->raiseonhover = 1;
|
||||
c->raisedelay = 250;
|
||||
c->htile = 50;
|
||||
c->vtile = 50;
|
||||
c->snapdist = 0;
|
||||
|
||||
10
cwmrc.5
10
cwmrc.5
@@ -401,6 +401,8 @@ 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
|
||||
@@ -409,6 +411,14 @@ 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
|
||||
|
||||
99
kbfunc.c
99
kbfunc.c
@@ -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_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)
|
||||
@@ -54,10 +55,21 @@ 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)
|
||||
{
|
||||
#define CWM_FACTOR 10
|
||||
#define CWM_FACTOR Conf.scalefactor
|
||||
|
||||
if (flags & CWM_BIGAMOUNT)
|
||||
amt *= CWM_FACTOR;
|
||||
@@ -165,7 +177,7 @@ kbfunc_client_move_mb(void *ctx, struct cargs *cargs)
|
||||
|
||||
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],
|
||||
CurrentTime) != GrabSuccess)
|
||||
return;
|
||||
@@ -242,6 +254,7 @@ 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;
|
||||
@@ -254,7 +267,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, cc->win, False, MOUSEMASK,
|
||||
if (XGrabPointer(X_Dpy, sc->rootwin, False, MOUSEMASK,
|
||||
GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_RESIZE],
|
||||
CurrentTime) != GrabSuccess)
|
||||
return;
|
||||
@@ -270,8 +283,8 @@ kbfunc_client_resize_mb(void *ctx, struct cargs *cargs)
|
||||
continue;
|
||||
ltime = ev.xmotion.time;
|
||||
|
||||
cc->geom.w = ev.xmotion.x;
|
||||
cc->geom.h = ev.xmotion.y;
|
||||
cc->geom.w = ev.xmotion.x - cc->geom.x - cc->bwidth;
|
||||
cc->geom.h = ev.xmotion.y - cc->geom.y - cc->bwidth;
|
||||
client_apply_sizehints(cc);
|
||||
client_resize(cc, 1);
|
||||
screen_prop_win_draw(sc,
|
||||
@@ -282,8 +295,19 @@ kbfunc_client_resize_mb(void *ctx, struct cargs *cargs)
|
||||
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);
|
||||
}
|
||||
screen_prop_win_destroy(sc);
|
||||
XUngrabPointer(X_Dpy, CurrentTime);
|
||||
|
||||
@@ -323,11 +347,74 @@ 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)
|
||||
{
|
||||
|
||||
24
parse.y
24
parse.y
@@ -71,9 +71,9 @@ 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 HTILE VTILE
|
||||
%token YES NO BORDERWIDTH MOVEAMOUNT SCALEFACTOR HTILE VTILE
|
||||
%token COLOR SNAPDIST
|
||||
%token ACTIVEBORDER INACTIVEBORDER URGENCYBORDER
|
||||
%token GROUPBORDER UNGROUPBORDER
|
||||
@@ -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");
|
||||
@@ -156,6 +166,13 @@ main : FONTNAME STRING {
|
||||
}
|
||||
conf->mamount = $2;
|
||||
}
|
||||
| SCALEFACTOR NUMBER {
|
||||
if ($2 < 0 || $2 > INT_MAX) {
|
||||
yyerror("invalid scalefactor");
|
||||
YYERROR;
|
||||
}
|
||||
conf->scalefactor = $2;
|
||||
}
|
||||
| SNAPDIST NUMBER {
|
||||
if ($2 < 0 || $2 > INT_MAX) {
|
||||
yyerror("invalid snapdist");
|
||||
@@ -350,6 +367,9 @@ lookup(char *s)
|
||||
{ "menufg", MENUFG},
|
||||
{ "moveamount", MOVEAMOUNT},
|
||||
{ "no", NO},
|
||||
{ "raise-delay", RAISEONHOVERDELAY},
|
||||
{ "raise-on-hover", RAISEONHOVER},
|
||||
{ "scalefactor", SCALEFACTOR},
|
||||
{ "selfont", FONTSELCOLOR},
|
||||
{ "snapdist", SNAPDIST},
|
||||
{ "sticky", STICKY},
|
||||
|
||||
107
xevents.c
107
xevents.c
@@ -33,7 +33,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "calmwm.h"
|
||||
|
||||
@@ -51,6 +51,12 @@ 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,
|
||||
@@ -68,8 +74,84 @@ void (*xev_handlers[LASTEvent])(XEvent *) = {
|
||||
[Expose] = xev_handle_expose,
|
||||
};
|
||||
|
||||
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 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 void
|
||||
xev_handle_maprequest(XEvent *ee)
|
||||
@@ -231,6 +313,21 @@ xev_handle_enternotify(XEvent *ee)
|
||||
|
||||
if ((cc = client_find(e->window)) != NULL)
|
||||
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
|
||||
@@ -247,6 +344,8 @@ 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) {
|
||||
@@ -489,5 +588,7 @@ 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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user