1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
|
/* evilwm - minimalist window manager for X11
* Copyright (C) 1999-2022 Ciaran Anscomb <evilwm@6809.org.uk>
* see README for license and other details. */
// Bindable functions
// All functions present the same call interface, so they can be mapped
// reasonably arbitrarily to user inputs.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "client.h"
#include "display.h"
#include "evilwm.h"
#include "func.h"
#include "list.h"
#include "log.h"
#include "screen.h"
#include "util.h"
static void do_client_move(struct client *c) {
if (abs(c->x) == c->border && c->oldw != 0)
c->x = 0;
if (abs(c->y) == c->border && c->oldh != 0)
c->y = 0;
if (c->width < c->min_width) {
c->width = c->min_width;
}
if (c->max_width && c->width > c->max_width) {
c->width = c->max_width;
}
if (c->height < c->min_height) {
c->height = c->min_height;
}
if (c->max_height && c->height > c->max_height) {
c->height = c->max_height;
}
client_moveresizeraise(c);
#ifdef WARP_POINTER
setmouse(c->window, c->width + c->border - 1, c->height + c->border - 1);
#endif
discard_enter_events(c);
}
void func_delete(void *sptr, XEvent *e, unsigned flags) {
if (!(flags & FL_CLIENT))
return;
struct client *c = sptr;
(void)e;
send_wm_delete(c, flags & FL_VALUEMASK);
}
void func_dock(void *sptr, XEvent *e, unsigned flags) {
if (!(flags & FL_SCREEN))
return;
struct screen *current_screen = sptr;
(void)e;
if (flags & FL_TOGGLE) {
set_docks_visible(current_screen, !current_screen->docks_visible);
}
}
void func_info(void *sptr, XEvent *e, unsigned flags) {
if (!(flags & FL_CLIENT))
return;
struct client *c = sptr;
client_show_info(c, e);
}
void func_lower(void *sptr, XEvent *e, unsigned flags) {
struct client *c = sptr;
if (!(flags & FL_CLIENT) || !c)
return;
(void)e;
client_lower(c);
}
void func_move(void *sptr, XEvent *e, unsigned flags) {
struct client *c = sptr;
if (!(flags & FL_CLIENT) || !c)
return;
struct monitor *monitor = client_monitor(c, NULL);
int width_inc = (c->width_inc > 1) ? c->width_inc : 16;
int height_inc = (c->height_inc > 1) ? c->height_inc : 16;
if (e->type == ButtonPress) {
XButtonEvent *xbutton = (XButtonEvent *)e;
client_move_drag(c, xbutton->button);
return;
}
if (flags & FL_RELATIVE) {
if (flags & FL_RIGHT) {
c->x += width_inc;
}
if (flags & FL_LEFT) {
c->x -= width_inc;
}
if (flags & FL_DOWN) {
c->y += height_inc;
}
if (flags & FL_UP) {
c->y -= height_inc;
}
} else {
if (flags & FL_RIGHT) {
c->x = monitor->x + monitor->width - c->width-c->border;
}
if (flags & FL_LEFT) {
c->x = monitor->x + c->border;
}
if (flags & FL_BOTTOM) {
c->y = monitor->y + monitor->height - c->height-c->border;
}
if (flags & FL_TOP) {
c->y = monitor->y + c->border;
}
}
do_client_move(c);
}
void func_next(void *sptr, XEvent *e, unsigned flags) {
(void)sptr;
(void)flags;
if (e->type != KeyPress)
return;
XKeyEvent *xkey = (XKeyEvent *)e;
client_select_next();
if (XGrabKeyboard(display.dpy, xkey->root, False, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess) {
XEvent ev;
do {
XMaskEvent(display.dpy, KeyPressMask|KeyReleaseMask, &ev);
if (ev.type == KeyPress && ev.xkey.keycode == xkey->keycode)
client_select_next();
} while (ev.type == KeyPress || ev.xkey.keycode == xkey->keycode);
XUngrabKeyboard(display.dpy, CurrentTime);
}
clients_tab_order = list_to_head(clients_tab_order, current);
}
void func_raise(void *sptr, XEvent *e, unsigned flags) {
struct client *c = sptr;
if (!(flags & FL_CLIENT) || !c)
return;
(void)e;
client_raise(c);
}
void func_resize(void *sptr, XEvent *e, unsigned flags) {
struct client *c = sptr;
if (!(flags & FL_CLIENT) || !c)
return;
int width_inc = (c->width_inc > 1) ? c->width_inc : 16;
int height_inc = (c->height_inc > 1) ? c->height_inc : 16;
if (e->type == ButtonPress) {
XButtonEvent *xbutton = (XButtonEvent *)e;
client_resize_sweep(c, xbutton->button);
return;
}
if (flags & FL_RELATIVE) {
if (flags & FL_RIGHT) {
c->width += width_inc;
}
if (flags & FL_LEFT) {
c->width -= width_inc;
}
if (flags & FL_DOWN) {
c->height += height_inc;
}
if (flags & FL_UP) {
c->height -= height_inc;
}
} else if (flags & FL_TOGGLE) {
int hv = 0;
if ((flags & FL_HORZ) == FL_HORZ) {
hv |= MAXIMISE_HORZ;
}
if ((flags & FL_VERT) == FL_VERT) {
hv |= MAXIMISE_VERT;
}
client_maximise(c, NET_WM_STATE_TOGGLE, hv);
return;
}
do_client_move(c);
}
void func_spawn(void *sptr, XEvent *e, unsigned flags) {
// TODO: configurable array of commands to run indexed by FL_VALUEMASK?
(void)sptr;
(void)e;
(void)flags;
spawn((const char *const *)option.term);
}
void func_vdesk(void *sptr, XEvent *e, unsigned flags) {
(void)e;
if (flags & FL_CLIENT) {
struct client *c = sptr;
if (flags & FL_TOGGLE) {
if (is_fixed(c)) {
client_to_vdesk(c, c->screen->vdesk);
} else {
client_to_vdesk(c, VDESK_FIXED);
}
}
} else if (flags & FL_SCREEN) {
struct screen *current_screen = sptr;
if (flags & FL_TOGGLE) {
switch_vdesk(current_screen, current_screen->old_vdesk);
} else if (flags & FL_RELATIVE) {
if (flags & FL_DOWN) {
if (current_screen->vdesk > 0) {
switch_vdesk(current_screen, current_screen->vdesk - 1);
}
}
if (flags & FL_UP) {
if (current_screen->vdesk < VDESK_MAX) {
switch_vdesk(current_screen, current_screen->vdesk + 1);
}
}
} else {
int v = flags & FL_VALUEMASK;
switch_vdesk(current_screen, v);
}
}
}
|