summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init.scm11
-rw-r--r--schewm.c165
-rw-r--r--wm.scm12
3 files changed, 88 insertions, 100 deletions
diff --git a/init.scm b/init.scm
index b24432d..932b6d7 100644
--- a/init.scm
+++ b/init.scm
@@ -3,8 +3,8 @@
(define config
(make-config
;; Border sizes
- 2 ; inner-border-width
- 0 ; outer-border-width
+ 4 ; (total) border-width
+ 2 ; outer-border-width
16 ; magnet-border-width
;; Margins
0 ; offset-x
@@ -22,16 +22,17 @@
(define (make-callback proc . args)
(lambda () (apply proc args)))
-(define terminal-cmd "xterm")
+(define terminal-cmd "alacritty")
(define menu-raw-callback
- (make-callback wm-exec-cmd "bemenu" "-b" "-s" "-l" "10" "-p" ">>>"))
+ (make-callback wm-exec-cmd "bemenu-run" "-b" "-s" "-l" "10" "-p" ">>>"))
(define menu-callback
(make-callback
wm-exec-cmd
"j4-dmenu-desktop"
- "--dmenu=bemenu -b -i -s -l 10 -p >>>"
+ ;; >>> must be escaped as it is interpreted by a shell (according to bemenu docs)
+ "--dmenu=bemenu -b -i -s -l 10 -p \\>\\>\\>"
(string-append "--term=" terminal-cmd)))
(define wm-keybindings
diff --git a/schewm.c b/schewm.c
index 82392a2..e73b0e8 100644
--- a/schewm.c
+++ b/schewm.c
@@ -602,7 +602,7 @@ callbacks_map_free(struct CallbacksMap *map) {
}
static struct Config {
- uint16_t inner_border_width, outer_border_width, magnet_border_width;
+ uint16_t border_width, outer_border_width, magnet_border_width;
int16_t offset_x, offset_y;
uint16_t offset_width, offset_height;
struct {
@@ -880,7 +880,7 @@ dpy_update_output(xcb_randr_output_t output,
// It is a new monitor
// XXX: should we care about name length?
- // int name_len = min(16, xcb_randr_get_output_info_name_length(output_info_reply.get()));
+ // int name_len = min(16, xcb_randr_get_output_info_name_length(o_reply));
const char *name = (const char *) xcb_randr_get_output_info_name(o_reply);
monitor = calloc(1, sizeof(struct Monitor));
if (monitor == NULL) {
@@ -914,7 +914,7 @@ dpy_update_outputs() {
xcb_randr_get_screen_resources_current(dpy.conn, dpy.screen->root);
xcb_randr_get_screen_resources_current_reply_t *s_reply =
xcb_randr_get_screen_resources_current_reply(dpy.conn, s_cookie, NULL);
- if (!s_reply) {
+ if (s_reply == NULL) {
return false;
}
@@ -927,20 +927,18 @@ dpy_update_outputs() {
xcb_randr_get_output_info(dpy.conn, outputs[i], timestamp);
xcb_randr_get_output_info_reply_t *o_reply =
xcb_randr_get_output_info_reply(dpy.conn, o_cookie, NULL);
- if (!o_reply) {
+ if (o_reply == NULL) {
continue;
}
if (o_reply->crtc == XCB_NONE) {
// Output no longer active, delete if we had any info about it
struct Monitor *monitor = dpy_find_monitor(outputs[i]);
- if (monitor == NULL) {
- continue;
+ if (monitor != NULL) {
+ dpy.monitors = monitor_ring_erase(dpy.monitors, monitor);
+ free(monitor);
+ any_change = true;
}
-
- dpy.monitors = monitor_ring_erase(dpy.monitors, monitor);
- free(monitor);
- any_change = true;
} else {
// New monitor or existing one changed its info
any_change = any_change || dpy_update_output(outputs[i], timestamp, o_reply);
@@ -964,12 +962,12 @@ mod_from_keycode(xcb_keycode_t keycode) {
xcb_get_modifier_mapping(dpy.conn);
xcb_get_modifier_mapping_reply_t *reply =
xcb_get_modifier_mapping_reply(dpy.conn, cookie, NULL);
- if (!reply || reply->keycodes_per_modifier == 0) {
+ if (reply == NULL || reply->keycodes_per_modifier == 0) {
goto mod_from_keycode_end;
}
xcb_keycode_t *mod_keycodes = xcb_get_modifier_mapping_keycodes(reply);
- if (!mod_keycodes) {
+ if (mod_keycodes == NULL) {
goto mod_from_keycode_end;
}
@@ -1029,6 +1027,25 @@ dpy_get_atom(const char *name) {
return atom;
}
+static xcb_cursor_t
+dpy_create_cursor(uint16_t glyph) {
+ xcb_cursor_t cursor = xcb_generate_id(dpy.conn);
+ xcb_create_glyph_cursor(
+ dpy.conn,
+ cursor,
+ dpy.cursor_font,
+ dpy.cursor_font,
+ glyph,
+ glyph + 1,
+ 0x3232,
+ 0x3232,
+ 0x3232,
+ 0xeeee,
+ 0xeeee,
+ 0xeeec);
+ return cursor;
+}
+
static bool
dpy_init(const char *wm_name) {
// This is initially NULL on purpose: we always try to dealloc
@@ -1132,34 +1149,8 @@ dpy_init(const char *wm_name) {
const char *cursor_font_name = "cursor";
dpy.cursor_font = xcb_generate_id(dpy.conn);
xcb_open_font(dpy.conn, dpy.cursor_font, strlen(cursor_font_name), cursor_font_name);
- dpy.fleur_cursor = xcb_generate_id(dpy.conn);
- xcb_create_glyph_cursor(
- dpy.conn,
- dpy.fleur_cursor,
- dpy.cursor_font,
- dpy.cursor_font,
- MOVE_GLYPH,
- MOVE_GLYPH + 1,
- 0x3232,
- 0x3232,
- 0x3232,
- 0xeeee,
- 0xeeee,
- 0xeeec);
- dpy.sizing_cursor = xcb_generate_id(dpy.conn);
- xcb_create_glyph_cursor(
- dpy.conn,
- dpy.sizing_cursor,
- dpy.cursor_font,
- dpy.cursor_font,
- RESIZE_GLYPH,
- RESIZE_GLYPH + 1,
- 0x3232,
- 0x3232,
- 0x3232,
- 0xeeee,
- 0xeeee,
- 0xeeec);
+ dpy.fleur_cursor = dpy_create_cursor(MOVE_GLYPH);
+ dpy.sizing_cursor = dpy_create_cursor(RESIZE_GLYPH);
xcb_event_mask_t event_mask = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT
| XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY
@@ -1359,7 +1350,7 @@ dpy_set_window_border_width(xcb_window_t window) {
dpy.conn,
window,
XCB_CONFIG_WINDOW_BORDER_WIDTH,
- &cfg.inner_border_width);
+ &cfg.border_width);
}
#define RECT_INIT(x, y, w, h) { \
@@ -1381,57 +1372,57 @@ dpy_draw_borders(struct Client *client, bool is_focused) {
RECT_INIT(
client->width,
0,
- cfg.inner_border_width - cfg.outer_border_width,
- client->height + cfg.inner_border_width - cfg.outer_border_width
+ cfg.border_width - cfg.outer_border_width,
+ client->height + cfg.border_width - cfg.outer_border_width
),
RECT_INIT(
- client->width + cfg.inner_border_width + cfg.outer_border_width,
+ client->width + cfg.border_width + cfg.outer_border_width,
0,
- cfg.inner_border_width - cfg.outer_border_width,
- client->height + cfg.inner_border_width - cfg.outer_border_width
+ cfg.border_width - cfg.outer_border_width,
+ client->height + cfg.border_width - cfg.outer_border_width
),
RECT_INIT(
0,
client->height,
- client->width + cfg.inner_border_width - cfg.outer_border_width,
- cfg.inner_border_width - cfg.outer_border_width
+ client->width + cfg.border_width - cfg.outer_border_width,
+ cfg.border_width - cfg.outer_border_width
),
RECT_INIT(
0,
- client->height + cfg.inner_border_width + cfg.outer_border_width,
- client->width + cfg.inner_border_width - cfg.outer_border_width,
- cfg.inner_border_width - cfg.outer_border_width
+ client->height + cfg.border_width + cfg.outer_border_width,
+ client->width + cfg.border_width - cfg.outer_border_width,
+ cfg.border_width - cfg.outer_border_width
),
RECT_INIT(
- client->width + cfg.inner_border_width + cfg.outer_border_width,
- client->height + cfg.inner_border_width + cfg.outer_border_width,
- cfg.inner_border_width,
- cfg.inner_border_width
+ client->width + cfg.border_width + cfg.outer_border_width,
+ client->height + cfg.border_width + cfg.outer_border_width,
+ cfg.border_width,
+ cfg.border_width
),
};
xcb_rectangle_t outer_rect[] = {
RECT_INIT(
- client->width + cfg.inner_border_width - cfg.outer_border_width,
+ client->width + cfg.border_width - cfg.outer_border_width,
0,
cfg.outer_border_width,
- client->height + cfg.inner_border_width * 2
+ client->height + cfg.border_width * 2
),
RECT_INIT(
- client->width + cfg.inner_border_width,
+ client->width + cfg.border_width,
0,
cfg.outer_border_width,
- client->height + cfg.inner_border_width * 2
+ client->height + cfg.border_width * 2
),
RECT_INIT(
0,
- client->height + cfg.inner_border_width - cfg.outer_border_width,
- client->width + cfg.inner_border_width * 2,
+ client->height + cfg.border_width - cfg.outer_border_width,
+ client->width + cfg.border_width * 2,
cfg.outer_border_width
),
RECT_INIT(
0,
- client->height + cfg.inner_border_width,
- client->width + cfg.inner_border_width * 2,
+ client->height + cfg.border_width,
+ client->width + cfg.border_width * 2,
cfg.outer_border_width
),
RECT_INIT(
@@ -1448,8 +1439,8 @@ dpy_draw_borders(struct Client *client, bool is_focused) {
dpy.screen->root_depth,
pixmap,
dpy.screen->root,
- client->width + cfg.inner_border_width * 2,
- client->height + cfg.inner_border_width * 2);
+ client->width + cfg.border_width * 2,
+ client->height + cfg.border_width * 2);
uint32_t color = client->is_unkillable
? cfg.colors.unkillable : cfg.colors.outer;
@@ -1664,14 +1655,12 @@ dpy_update_window_list(const struct ClientsMap *clients) {
xcb_window_t *windows = NULL;
size_t num_windows = 0;
if (clients->size != 0) {
- fprintf(stderr, "window_list:\n");
windows = malloc(clients->size * sizeof(xcb_window_t));
for (size_t i = 0; i < clients->num_buckets; i++) {
for (struct ClientList *list = clients->buckets[i];
list != NULL;
list = list->next) {
windows[num_windows++] = list->client->id;
- fprintf(stderr, "\twindow: %x\n", list->client->id);
}
}
}
@@ -1954,8 +1943,8 @@ wm_set_client_state(struct Client *client, enum WindowState state) {
wm_client_monitor_size(client, true, &mon_rect);
client->x = mon_rect.x;
client->y = mon_rect.y;
- client->width = mon_rect.width - cfg.inner_border_width * 2;
- client->height = mon_rect.height - cfg.inner_border_width * 2;
+ client->width = mon_rect.width - cfg.border_width * 2;
+ client->height = mon_rect.height - cfg.border_width * 2;
}
dpy_update_window_geometry(client);
break;
@@ -1977,15 +1966,15 @@ wm_move_client(struct Client *client, int16_t dx, int16_t dy, bool in_monitor) {
// Complete movement by checking for magnets
if (client->x < cfg.magnet_border_width + mon_rect.x) {
client->x = mon_rect.x;
- } else if (client->x + client->width + cfg.inner_border_width >
+ } else if (client->x + client->width + cfg.border_width >
mon_rect.x + mon_rect.width - cfg.magnet_border_width) {
- client->x = mon_rect.x + mon_rect.width - client->width - cfg.inner_border_width * 2;
+ client->x = mon_rect.x + mon_rect.width - client->width - cfg.border_width * 2;
}
if (client->y < cfg.magnet_border_width + mon_rect.y) {
client->y = mon_rect.y;
- } else if (client->y + client->height + cfg.inner_border_width >
+ } else if (client->y + client->height + cfg.border_width >
mon_rect.y + mon_rect.height - cfg.magnet_border_width) {
- client->y = mon_rect.y + mon_rect.height - client->height - cfg.inner_border_width * 2;
+ client->y = mon_rect.y + mon_rect.height - client->height - cfg.border_width * 2;
}
}
dpy_update_window_position(client);
@@ -2006,13 +1995,13 @@ wm_resize_client(struct Client *client,
if (in_monitor) {
struct Rect mon_rect;
wm_client_monitor_size(client, true, &mon_rect);
- if (client->x + client->width + cfg.inner_border_width >
+ if (client->x + client->width + cfg.border_width >
mon_rect.x + mon_rect.width) {
- client->width = mon_rect.width - ((client->x - mon_rect.x) + cfg.inner_border_width * 2);
+ client->width = mon_rect.width - ((client->x - mon_rect.x) + cfg.border_width * 2);
}
- if (client->y + client->height + cfg.inner_border_width >
+ if (client->y + client->height + cfg.border_width >
mon_rect.y + mon_rect.height) {
- client->height = mon_rect.height - ((client->y - mon_rect.y) + cfg.inner_border_width * 2);
+ client->height = mon_rect.height - ((client->y - mon_rect.y) + cfg.border_width * 2);
}
}
dpy_update_window_size(client);
@@ -2057,11 +2046,11 @@ wm_fit_client(struct Client *client) {
bool should_move = false;
// Check if client is located outside monitor coords
if (client->x > mon_rect.x + mon_rect.width) {
- client->x = mon_rect.x + mon_rect.width - client->width - cfg.inner_border_width * 2;
+ client->x = mon_rect.x + mon_rect.width - client->width - cfg.border_width * 2;
should_move = true;
}
if (client->y > mon_rect.y + mon_rect.height) {
- client->y = mon_rect.y + mon_rect.height - client->height - cfg.inner_border_width * 2;
+ client->y = mon_rect.y + mon_rect.height - client->height - cfg.border_width * 2;
should_move = true;
}
if (client->x < mon_rect.x) {
@@ -2076,7 +2065,7 @@ wm_fit_client(struct Client *client) {
// Check if client is larger than monitor, if so move to upper corner and
// resize to fill
bool should_resize = wm_apply_size_hints(client);
- uint16_t border_width = client->should_ignore_borders ? 0 : cfg.inner_border_width;
+ uint16_t border_width = client->should_ignore_borders ? 0 : cfg.border_width;
if (client->width + border_width * 2 > mon_rect.width) {
client->x = mon_rect.x;
client->width = mon_rect.width - border_width * 2;
@@ -2331,7 +2320,7 @@ wm_destroy() {
}
void
-wm_reconfigure(uint16_t inner_border_width,
+wm_reconfigure(uint16_t border_width,
uint16_t outer_border_width,
uint16_t magnet_border_width,
int16_t offset_x,
@@ -2343,7 +2332,7 @@ wm_reconfigure(uint16_t inner_border_width,
uint32_t unkillable,
uint32_t empty,
uint32_t outer) {
- cfg.inner_border_width = inner_border_width;
+ cfg.border_width = border_width;
cfg.outer_border_width = outer_border_width;
cfg.magnet_border_width = magnet_border_width;
cfg.offset_x = offset_x;
@@ -2527,8 +2516,8 @@ wm_toggle_tile(enum TileType tile_type) {
break;
}
// Correct width/height according to borders
- rect.width -= cfg.inner_border_width * 2;
- rect.height -= cfg.inner_border_width * 2;
+ rect.width -= cfg.border_width * 2;
+ rect.height -= cfg.border_width * 2;
// Stores current size so we can toggle it later
client_store_size(wm.focus);
wm_move_resize_client(wm.focus, &rect, false);
@@ -2597,13 +2586,13 @@ wm_pack_client(enum PackType pack_type) {
dx = rect.x - wm.focus->x;
break;
case PACK_RIGHT:
- dx = rect.width - (wm.focus->x - rect.x + wm.focus->width) - cfg.inner_border_width * 2;
+ dx = rect.width - (wm.focus->x - rect.x + wm.focus->width) - cfg.border_width * 2;
break;
case PACK_TOP:
dy = rect.y - wm.focus->y;
break;
case PACK_BOTTOM:
- dy = rect.height - (wm.focus->y - rect.y + wm.focus->height) - cfg.inner_border_width * 2;
+ dy = rect.height - (wm.focus->y - rect.y + wm.focus->height) - cfg.border_width * 2;
break;
}
wm_move_client(wm.focus, dx, dy, false);
@@ -2818,10 +2807,8 @@ ev_configure_request(xcb_generic_event_t *generic_ev) {
}
wm_apply_size_hints(client);
dpy_update_window_geometry(client);
- wm_update_client_monitor(client);
-
- // TODO: do we need this?
dpy_draw_borders(client, wm.focus == client);
+ wm_update_client_monitor(client);
}
}
diff --git a/wm.scm b/wm.scm
index 40b5d1d..5b4a313 100644
--- a/wm.scm
+++ b/wm.scm
@@ -38,7 +38,7 @@
;; Configuration record
(define-record-type <wm-config>
(make-config
- inner-border-width
+ border-width
outer-border-width
magnet-border-width
offset-x
@@ -51,9 +51,9 @@
empty-color
outer-color)
wm-config?
- (inner-border-width config-inner-border-width set-config-inner-border-width!)
- (outer-border-width config-outer-border-width set-config-outer-border-width!)
- (magnet-border-width config-magnet-border-width set-config-magnet-border-width!)
+ (border-width config-border-width set-config-border-width!)
+ (outer-border-width config-outer-border-width set-config-outer-border-width!)
+ (magnet-border-width config-magnet-border-width set-config-magnet-border-width!)
(offset-x config-offset-x set-config-offset-x!)
(offset-y config-offset-y set-config-offset-y!)
(offset-width config-offset-width set-config-offset-width!)
@@ -113,7 +113,7 @@
uint32)))
(define (wm-reconfigure config)
- (c/wm-reconfigure (config-inner-border-width config)
+ (c/wm-reconfigure (config-border-width config)
(config-outer-border-width config)
(config-magnet-border-width config)
(config-offset-x config)
@@ -244,4 +244,4 @@
(define (wm-exec-cmd . args)
(when (eq? (primitive-fork) 0)
- (apply execlp (cons (car args) args))))
+ (apply execlp (car args) args)))