From c8823dafdf66de347d145093bb5ae3aed03b914a Mon Sep 17 00:00:00 2001 From: Michael Czigler <37268479+mcpcpc@users.noreply.github.com> Date: Thu, 12 Nov 2020 09:12:58 -0500 Subject: [PATCH] released at 0.0.6 --- CHANGELOG | 8 ++++++-- TODO | 2 -- config.h | 20 ++++++++++++-------- xwm.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- xwm.h | 8 ++++++++ 5 files changed, 66 insertions(+), 22 deletions(-) delete mode 100644 TODO diff --git a/CHANGELOG b/CHANGELOG index 39ebf66..6f7e7b1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,7 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - string.h library dependency. -## [0.0.4] - 20202-11-10 +## [0.0.4] - 2020-11-10 ### Added - Instructions for patches and the patching process. - Minimum window height and width parameters. @@ -34,7 +34,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Crash when pointer x/y cords less than window origin. -## [0.0.5] - 20202-11-11 +## [0.0.5] - 2020-11-11 ### Added - Default key bindings in man page. - Disclaimer section in README. + +## [0.0.6] - 2020-11-12 +### Added +- Window borders and color definitions. diff --git a/TODO b/TODO deleted file mode 100644 index 777b391..0000000 --- a/TODO +++ /dev/null @@ -1,2 +0,0 @@ -* Add borders to indicate window focus (as a patch?) -* Add workspaces (as patch) diff --git a/config.h b/config.h index 51e224c..e7b074f 100644 --- a/config.h +++ b/config.h @@ -13,18 +13,21 @@ * XCB_MOD_MASK_ANY */ -#define MOD1 XCB_MOD_MASK_4 -#define MOD2 XCB_MOD_MASK_SHIFT +#define MOD1 XCB_MOD_MASK_4 +#define MOD2 XCB_MOD_MASK_SHIFT /* DEFAULT WINDOW PROPERTIES - * The following parameters can be used to change window and new - * window behavior + * The following parameters can be used to change existing and new + * window behavior. */ -#define WINDOW_WIDTH 600 -#define WINDOW_HEIGHT 400 -#define WINDOW_MIN_WIDTH 60 -#define WINDOW_MIN_HEIGHT 40 +#define WINDOW_WIDTH 600 +#define WINDOW_HEIGHT 400 +#define WINDOW_MIN_WIDTH 60 +#define WINDOW_MIN_HEIGHT 40 +#define BORDER_WIDTH 2 /* 0 = no border effect */ +#define BORDER_COLOR_UNFOCUSED 0x00FFFF /* 0xRRGGBB */ +#define BORDER_COLOR_FOCUSED 0xFFFFFF /* 0xRRGGBB */ /* ALIASED COMMANDS * Each space delimited argument should be passed as an additional @@ -50,3 +53,4 @@ static Key keys[] = { { MOD1, 0x0071, killclient, NULL }, /* 0x0071 = XK_q */ { MOD1|MOD2, 0x0071, closewm, NULL } /* 0x0071 = XK_q */ }; + diff --git a/xwm.c b/xwm.c index 3eaa11a..12f3db1 100644 --- a/xwm.c +++ b/xwm.c @@ -104,6 +104,35 @@ static void setFocus(xcb_drawable_t window) { } } +static void setBorderColor(xcb_window_t window, int focus) { + if ((BORDER_WIDTH > 0) && (scre->root != window) && (0 != window)) { + uint32_t vals[1]; + vals[0] = focus ? BORDER_COLOR_FOCUSED : BORDER_COLOR_UNFOCUSED; + xcb_change_window_attributes(dpy, window, XCB_CW_BORDER_PIXEL, vals); + xcb_flush(dpy); + } +} + +static void setBorderWidth(xcb_window_t window) { + if ((BORDER_WIDTH > 0) && (scre->root != window) && (0 != window)) { + uint32_t vals[2]; + vals[0] = BORDER_WIDTH; + xcb_configure_window(dpy, window, XCB_CONFIG_WINDOW_BORDER_WIDTH, vals); + xcb_flush(dpy); + } +} + +static void setWindowDimensions(xcb_window_t window) { + if ((scre->root != window) && (0 != window)) { + uint32_t vals[2]; + vals[0] = WINDOW_WIDTH; + vals[1] = WINDOW_HEIGHT; + xcb_configure_window(dpy, window, XCB_CONFIG_WINDOW_WIDTH | + XCB_CONFIG_WINDOW_HEIGHT, vals); + xcb_flush(dpy); + } +} + static void handleKeyPress(xcb_generic_event_t * ev) { xcb_key_press_event_t * e = ( xcb_key_press_event_t *) ev; xcb_keysym_t keysym = xcb_get_keysym(e->detail); @@ -119,6 +148,12 @@ static void handleKeyPress(xcb_generic_event_t * ev) { static void handleEnterNotify(xcb_generic_event_t * ev) { xcb_enter_notify_event_t * e = ( xcb_enter_notify_event_t *) ev; setFocus(e->event); + setBorderColor(e->event, 1); +} + +static void handleLeaveNotify(xcb_generic_event_t * ev) { + xcb_leave_notify_event_t * e = ( xcb_leave_notify_event_t *) ev; + setBorderColor(e->event, 0); } static void handleButtonRelease(xcb_generic_event_t * ev) { @@ -137,15 +172,10 @@ static void handleDestroyNotify(xcb_generic_event_t * ev) { static void handleMapRequest(xcb_generic_event_t * ev) { xcb_map_request_event_t * e = (xcb_map_request_event_t *) ev; xcb_map_window(dpy, e->window); - if ((scre->root != e->window) && (0 != e->window)) { - uint32_t vals[2]; - vals[0] = WINDOW_WIDTH; - vals[1] = WINDOW_HEIGHT; - xcb_configure_window(dpy, e->window, XCB_CONFIG_WINDOW_WIDTH | - XCB_CONFIG_WINDOW_HEIGHT, vals); - xcb_flush(dpy); - } - values[0] = XCB_EVENT_MASK_ENTER_WINDOW; + setWindowDimensions(e->window); + setBorderWidth(e->window); + setBorderColor(e->window, 0); + values[0] = XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW; xcb_change_window_attributes_checked(dpy, e->window, XCB_CW_EVENT_MASK, values); setFocus(e->window); @@ -221,7 +251,7 @@ static int strcmp_c(char * str1, char * str2) { int main(int argc, char * argv[]) { int ret = 0; if ((argc == 2) && (strcmp_c("-v", argv[1]) == 0)) { - ret = die("xwm-0.0.5, © 2020 Michael Czigler, see LICENSE for details\n"); + ret = die("xwm-0.0.6, © 2020 Michael Czigler, see LICENSE for details\n"); } if ((ret == 0) && (argc != 1)) { ret = die("usage: xwm [-v]\n"); diff --git a/xwm.h b/xwm.h index ad2c11c..77d2eee 100644 --- a/xwm.h +++ b/xwm.h @@ -22,10 +22,17 @@ static void killclient(char **com); static void spawn(char **com); static void closewm(char ** com); +/* window behavior */ +static void setFocus(xcb_drawable_t window); +static void setWindowDimensions(xcb_drawable_t window); +static void setBorderWidth(xcb_drawable_t window); +static void setBorderColor(xcb_drawable_t window, int focus); + /* event hander actions */ static int eventHandler(void); static void handleMotionNotify(xcb_generic_event_t * ev); static void handleEnterNotify(xcb_generic_event_t * ev); +static void handleLeaveNotify(xcb_generic_event_t * ev); static void handleDestroyNotify(xcb_generic_event_t * ev); static void handleButtonPress(xcb_generic_event_t * ev); static void handleButtonRelease(xcb_generic_event_t * ev); @@ -35,6 +42,7 @@ static void handleMapRequest(xcb_generic_event_t * ev); static handler_func_t handler_funs[] = { { XCB_MOTION_NOTIFY, handleMotionNotify }, { XCB_ENTER_NOTIFY, handleEnterNotify }, + { XCB_LEAVE_NOTIFY, handleLeaveNotify }, { XCB_DESTROY_NOTIFY, handleDestroyNotify }, { XCB_BUTTON_PRESS, handleButtonPress }, { XCB_BUTTON_RELEASE, handleButtonRelease },