Skip to content

Commit c8823da

Browse files
authored
released at 0.0.6
1 parent 90dd85f commit c8823da

File tree

5 files changed

+66
-22
lines changed

5 files changed

+66
-22
lines changed

CHANGELOG

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
### Removed
2424
- string.h library dependency.
2525

26-
## [0.0.4] - 20202-11-10
26+
## [0.0.4] - 2020-11-10
2727
### Added
2828
- Instructions for patches and the patching process.
2929
- Minimum window height and width parameters.
@@ -34,7 +34,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3434
### Fixed
3535
- Crash when pointer x/y cords less than window origin.
3636

37-
## [0.0.5] - 20202-11-11
37+
## [0.0.5] - 2020-11-11
3838
### Added
3939
- Default key bindings in man page.
4040
- Disclaimer section in README.
41+
42+
## [0.0.6] - 2020-11-12
43+
### Added
44+
- Window borders and color definitions.

TODO

-2
This file was deleted.

config.h

+12-8
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@
1313
* XCB_MOD_MASK_ANY
1414
*/
1515

16-
#define MOD1 XCB_MOD_MASK_4
17-
#define MOD2 XCB_MOD_MASK_SHIFT
16+
#define MOD1 XCB_MOD_MASK_4
17+
#define MOD2 XCB_MOD_MASK_SHIFT
1818

1919
/* DEFAULT WINDOW PROPERTIES
20-
* The following parameters can be used to change window and new
21-
* window behavior
20+
* The following parameters can be used to change existing and new
21+
* window behavior.
2222
*/
2323

24-
#define WINDOW_WIDTH 600
25-
#define WINDOW_HEIGHT 400
26-
#define WINDOW_MIN_WIDTH 60
27-
#define WINDOW_MIN_HEIGHT 40
24+
#define WINDOW_WIDTH 600
25+
#define WINDOW_HEIGHT 400
26+
#define WINDOW_MIN_WIDTH 60
27+
#define WINDOW_MIN_HEIGHT 40
28+
#define BORDER_WIDTH 2 /* 0 = no border effect */
29+
#define BORDER_COLOR_UNFOCUSED 0x00FFFF /* 0xRRGGBB */
30+
#define BORDER_COLOR_FOCUSED 0xFFFFFF /* 0xRRGGBB */
2831

2932
/* ALIASED COMMANDS
3033
* Each space delimited argument should be passed as an additional
@@ -50,3 +53,4 @@ static Key keys[] = {
5053
{ MOD1, 0x0071, killclient, NULL }, /* 0x0071 = XK_q */
5154
{ MOD1|MOD2, 0x0071, closewm, NULL } /* 0x0071 = XK_q */
5255
};
56+

xwm.c

+40-10
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,35 @@ static void setFocus(xcb_drawable_t window) {
104104
}
105105
}
106106

107+
static void setBorderColor(xcb_window_t window, int focus) {
108+
if ((BORDER_WIDTH > 0) && (scre->root != window) && (0 != window)) {
109+
uint32_t vals[1];
110+
vals[0] = focus ? BORDER_COLOR_FOCUSED : BORDER_COLOR_UNFOCUSED;
111+
xcb_change_window_attributes(dpy, window, XCB_CW_BORDER_PIXEL, vals);
112+
xcb_flush(dpy);
113+
}
114+
}
115+
116+
static void setBorderWidth(xcb_window_t window) {
117+
if ((BORDER_WIDTH > 0) && (scre->root != window) && (0 != window)) {
118+
uint32_t vals[2];
119+
vals[0] = BORDER_WIDTH;
120+
xcb_configure_window(dpy, window, XCB_CONFIG_WINDOW_BORDER_WIDTH, vals);
121+
xcb_flush(dpy);
122+
}
123+
}
124+
125+
static void setWindowDimensions(xcb_window_t window) {
126+
if ((scre->root != window) && (0 != window)) {
127+
uint32_t vals[2];
128+
vals[0] = WINDOW_WIDTH;
129+
vals[1] = WINDOW_HEIGHT;
130+
xcb_configure_window(dpy, window, XCB_CONFIG_WINDOW_WIDTH |
131+
XCB_CONFIG_WINDOW_HEIGHT, vals);
132+
xcb_flush(dpy);
133+
}
134+
}
135+
107136
static void handleKeyPress(xcb_generic_event_t * ev) {
108137
xcb_key_press_event_t * e = ( xcb_key_press_event_t *) ev;
109138
xcb_keysym_t keysym = xcb_get_keysym(e->detail);
@@ -119,6 +148,12 @@ static void handleKeyPress(xcb_generic_event_t * ev) {
119148
static void handleEnterNotify(xcb_generic_event_t * ev) {
120149
xcb_enter_notify_event_t * e = ( xcb_enter_notify_event_t *) ev;
121150
setFocus(e->event);
151+
setBorderColor(e->event, 1);
152+
}
153+
154+
static void handleLeaveNotify(xcb_generic_event_t * ev) {
155+
xcb_leave_notify_event_t * e = ( xcb_leave_notify_event_t *) ev;
156+
setBorderColor(e->event, 0);
122157
}
123158

124159
static void handleButtonRelease(xcb_generic_event_t * ev) {
@@ -137,15 +172,10 @@ static void handleDestroyNotify(xcb_generic_event_t * ev) {
137172
static void handleMapRequest(xcb_generic_event_t * ev) {
138173
xcb_map_request_event_t * e = (xcb_map_request_event_t *) ev;
139174
xcb_map_window(dpy, e->window);
140-
if ((scre->root != e->window) && (0 != e->window)) {
141-
uint32_t vals[2];
142-
vals[0] = WINDOW_WIDTH;
143-
vals[1] = WINDOW_HEIGHT;
144-
xcb_configure_window(dpy, e->window, XCB_CONFIG_WINDOW_WIDTH |
145-
XCB_CONFIG_WINDOW_HEIGHT, vals);
146-
xcb_flush(dpy);
147-
}
148-
values[0] = XCB_EVENT_MASK_ENTER_WINDOW;
175+
setWindowDimensions(e->window);
176+
setBorderWidth(e->window);
177+
setBorderColor(e->window, 0);
178+
values[0] = XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW;
149179
xcb_change_window_attributes_checked(dpy, e->window,
150180
XCB_CW_EVENT_MASK, values);
151181
setFocus(e->window);
@@ -221,7 +251,7 @@ static int strcmp_c(char * str1, char * str2) {
221251
int main(int argc, char * argv[]) {
222252
int ret = 0;
223253
if ((argc == 2) && (strcmp_c("-v", argv[1]) == 0)) {
224-
ret = die("xwm-0.0.5, © 2020 Michael Czigler, see LICENSE for details\n");
254+
ret = die("xwm-0.0.6, © 2020 Michael Czigler, see LICENSE for details\n");
225255
}
226256
if ((ret == 0) && (argc != 1)) {
227257
ret = die("usage: xwm [-v]\n");

xwm.h

+8
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ static void killclient(char **com);
2222
static void spawn(char **com);
2323
static void closewm(char ** com);
2424

25+
/* window behavior */
26+
static void setFocus(xcb_drawable_t window);
27+
static void setWindowDimensions(xcb_drawable_t window);
28+
static void setBorderWidth(xcb_drawable_t window);
29+
static void setBorderColor(xcb_drawable_t window, int focus);
30+
2531
/* event hander actions */
2632
static int eventHandler(void);
2733
static void handleMotionNotify(xcb_generic_event_t * ev);
2834
static void handleEnterNotify(xcb_generic_event_t * ev);
35+
static void handleLeaveNotify(xcb_generic_event_t * ev);
2936
static void handleDestroyNotify(xcb_generic_event_t * ev);
3037
static void handleButtonPress(xcb_generic_event_t * ev);
3138
static void handleButtonRelease(xcb_generic_event_t * ev);
@@ -35,6 +42,7 @@ static void handleMapRequest(xcb_generic_event_t * ev);
3542
static handler_func_t handler_funs[] = {
3643
{ XCB_MOTION_NOTIFY, handleMotionNotify },
3744
{ XCB_ENTER_NOTIFY, handleEnterNotify },
45+
{ XCB_LEAVE_NOTIFY, handleLeaveNotify },
3846
{ XCB_DESTROY_NOTIFY, handleDestroyNotify },
3947
{ XCB_BUTTON_PRESS, handleButtonPress },
4048
{ XCB_BUTTON_RELEASE, handleButtonRelease },

0 commit comments

Comments
 (0)