Skip to content

Commit 10ace95

Browse files
authored
released at 0.0.9
1 parent 41ba4a6 commit 10ace95

File tree

4 files changed

+32
-40
lines changed

4 files changed

+32
-40
lines changed

CHANGELOG

+5
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5454
### Removed
5555
- Global root variable.
5656
- Removed leave notify event.
57+
58+
## [0.0.9] - 2020-11-17
59+
### Fixed
60+
- Window resize lag.
61+
- Bug where window border moves outside of root window.

config.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
* 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_X 600
25+
#define WINDOW_Y 400
26+
#define WINDOW_MIN_X 60
27+
#define WINDOW_MIN_Y 40
2828
#define BORDER_WIDTH 1 /* 0 = no border effect */
2929
#define BORDER_COLOR_UNFOCUSED 0x696969 /* 0xRRGGBB */
3030
#define BORDER_COLOR_FOCUSED 0xFFFFFF /* 0xRRGGBB */

xwm.c

+23-34
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,31 @@ static void handleButtonPress(xcb_generic_event_t * ev) {
5050
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, scre->root, XCB_NONE, XCB_CURRENT_TIME);
5151
}
5252

53-
static void moveWindow(xcb_query_pointer_reply_t * poin) {
54-
xcb_get_geometry_cookie_t geom_now = xcb_get_geometry(dpy, win);
55-
xcb_get_geometry_reply_t * geom = xcb_get_geometry_reply(dpy, geom_now, NULL);
56-
values[0] = ((poin->root_x + geom->width) > scre->width_in_pixels) ?
57-
(scre->width_in_pixels - geom->width) : poin->root_x;
58-
values[1] = ((poin->root_y + geom->height) > scre->height_in_pixels) ?
59-
(scre->height_in_pixels - geom->height) : poin->root_y;
60-
xcb_configure_window(dpy, win, XCB_CONFIG_WINDOW_X
61-
| XCB_CONFIG_WINDOW_Y, values);
62-
}
63-
64-
static void resizeWindow(xcb_query_pointer_reply_t * poin) {
65-
xcb_get_geometry_cookie_t geom_now = xcb_get_geometry(dpy, win);
66-
xcb_get_geometry_reply_t* geom = xcb_get_geometry_reply(dpy, geom_now, NULL);
67-
if (!((poin->root_x <= geom->x) || (poin->root_y <= geom->y))) {
68-
values[0] = poin->root_x - geom->x;
69-
values[1] = poin->root_y - geom->y;
70-
uint32_t min_x = WINDOW_MIN_WIDTH;
71-
uint32_t min_y = WINDOW_MIN_HEIGHT;
72-
if ((values[0] >= min_x) && (values[1] >= min_y)) {
73-
xcb_configure_window(dpy, win, XCB_CONFIG_WINDOW_WIDTH
74-
| XCB_CONFIG_WINDOW_HEIGHT, values);
75-
}
76-
}
77-
}
78-
7953
static void handleMotionNotify(xcb_generic_event_t * ev) {
8054
xcb_query_pointer_cookie_t coord = xcb_query_pointer(dpy, scre->root);
8155
xcb_query_pointer_reply_t * poin = xcb_query_pointer_reply(dpy, coord, 0);
8256
uint32_t val[2] = {1, 3};
8357
if ((values[2] == val[0]) && (win != 0)) {
84-
moveWindow(poin);
85-
}
86-
if ((values[2] == val[1]) && (win != 0)) {
87-
resizeWindow(poin);
88-
}
58+
xcb_get_geometry_cookie_t geom_now = xcb_get_geometry(dpy, win);
59+
xcb_get_geometry_reply_t * geom = xcb_get_geometry_reply(dpy, geom_now, NULL);
60+
values[0] = ((poin->root_x + geom->width + 2*BORDER_WIDTH) > scre->width_in_pixels) ?
61+
(scre->width_in_pixels - geom->width - 2*BORDER_WIDTH) : poin->root_x;
62+
values[1] = ((poin->root_y + geom->height + 2*BORDER_WIDTH) > scre->height_in_pixels) ?
63+
(scre->height_in_pixels - geom->height - 2*BORDER_WIDTH) : poin->root_y;
64+
xcb_configure_window(dpy, win, XCB_CONFIG_WINDOW_X
65+
| XCB_CONFIG_WINDOW_Y, values);
66+
} else if ((values[2] == val[1]) && (win != 0)) {
67+
xcb_get_geometry_cookie_t geom_now = xcb_get_geometry(dpy, win);
68+
xcb_get_geometry_reply_t* geom = xcb_get_geometry_reply(dpy, geom_now, NULL);
69+
if (!((poin->root_x <= geom->x) || (poin->root_y <= geom->y))) {
70+
values[0] = poin->root_x - geom->x - BORDER_WIDTH;
71+
values[1] = poin->root_y - geom->y - BORDER_WIDTH;
72+
if ((values[0] >= WINDOW_MIN_X) && (values[1] >= WINDOW_MIN_Y)) {
73+
xcb_configure_window(dpy, win, XCB_CONFIG_WINDOW_WIDTH
74+
| XCB_CONFIG_WINDOW_HEIGHT, values);
75+
}
76+
}
77+
} else {}
8978
}
9079

9180
static xcb_keycode_t * xcb_get_keycodes(xcb_keysym_t keysym) {
@@ -132,8 +121,8 @@ static void setBorderWidth(xcb_window_t window) {
132121
static void setWindowDimensions(xcb_window_t window) {
133122
if ((scre->root != window) && (0 != window)) {
134123
uint32_t vals[2];
135-
vals[0] = WINDOW_WIDTH;
136-
vals[1] = WINDOW_HEIGHT;
124+
vals[0] = WINDOW_X;
125+
vals[1] = WINDOW_Y;
137126
xcb_configure_window(dpy, window, XCB_CONFIG_WINDOW_WIDTH |
138127
XCB_CONFIG_WINDOW_HEIGHT, vals);
139128
xcb_flush(dpy);
@@ -259,7 +248,7 @@ static int strcmp_c(char * str1, char * str2) {
259248
int main(int argc, char * argv[]) {
260249
int ret = 0;
261250
if ((argc == 2) && (strcmp_c("-v", argv[1]) == 0)) {
262-
ret = die("xwm-0.0.8, © 2020 Michael Czigler, see LICENSE for details\n");
251+
ret = die("xwm-0.0.9, © 2020 Michael Czigler, see LICENSE for details\n");
263252
}
264253
if ((ret == 0) && (argc != 1)) {
265254
ret = die("usage: xwm [-v]\n");

xwm.h

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ static void setFocus(xcb_drawable_t window);
2727
static void setWindowDimensions(xcb_drawable_t window);
2828
static void setBorderWidth(xcb_drawable_t window);
2929
static void setBorderColor(xcb_drawable_t window, int focus);
30-
static void moveWindow(xcb_query_pointer_reply_t * poin);
31-
static void resizeWindow(xcb_query_pointer_reply_t * poin);
3230

3331
/* event hander actions */
3432
static int eventHandler(void);

0 commit comments

Comments
 (0)