Skip to content

Commit

Permalink
released at 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpcpc authored Nov 7, 2020
1 parent 040610d commit 265a5cb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial release.

## [0.0.2] - 2020-11-07
## Added
- Close window command (default: Win+q)

### Fixed
- Resize crash in root window.
6 changes: 3 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BUILD REQUIREMENTS
==================

Other than libxcb, xwm also uses several default utilities which can be
patched or configured to the users preference.
patched, configured or expanded to meet the users preference.

application launcher dmenu - https://git.suckless.org/dmenu
terminal emulator st - https://git.suckless.org/st
Expand All @@ -20,11 +20,12 @@ patched or configured to the users preference.
COMMANDS
========

Implemented commands are limited.
Implemented commands:
Win+Button1+[drag] interactive window move
Win+Button3+[drag] interactive window resize
Win+Space run launcher menu (default: dmenu_run)
Win+Enter create new terminal window (default: st)
Win+q kill focused window
Win+Shift+q quit window manager

INSTALL
Expand Down Expand Up @@ -63,4 +64,3 @@ CONTACT
=======

For questions or issues, please contact info[at]mcpcpc[dot]com.

3 changes: 1 addition & 2 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
* Fix minimum window size
* Add close window command (e.g. Win+q)
* Add minimum window size
* Use library call instead of execvp()
24 changes: 18 additions & 6 deletions xwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ static xcb_drawable_t root;
static uint32_t values[3];

static void killclient(char **com) {
xcb_kill_client(dpy, win);
}

static void closewm(char **com) {
Expand All @@ -33,7 +34,7 @@ static void spawn(char **com) {
}

static void eventHandlerButtonPress(xcb_generic_event_t * ev) {
xcb_button_press_event_t * e = ( xcb_button_press_event_t *) ev;
xcb_button_press_event_t * e = (xcb_button_press_event_t *) ev;
win = e->child;
values[0] = XCB_STACK_MODE_ABOVE;
xcb_configure_window(dpy, win, XCB_CONFIG_WINDOW_STACK_MODE, values);
Expand All @@ -42,10 +43,11 @@ static void eventHandlerButtonPress(xcb_generic_event_t * ev) {
if (1 == e->detail) {
values[2] = 1;
xcb_warp_pointer(dpy, XCB_NONE, win, 0, 0, 0, 0, 1, 1);
} else {
} else if (win != 0) {
values[2] = 3;
xcb_warp_pointer(dpy, XCB_NONE, win, 0, 0, 0, 0, geom->width, geom->height);
}
else {}
xcb_grab_pointer(dpy, 0, root, XCB_EVENT_MASK_BUTTON_RELEASE
| XCB_EVENT_MASK_BUTTON_MOTION | XCB_EVENT_MASK_POINTER_MOTION_HINT,
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, root, XCB_NONE, XCB_CURRENT_TIME);
Expand All @@ -55,7 +57,7 @@ static void eventHandlerMotionNotify(xcb_generic_event_t * ev) {
xcb_query_pointer_cookie_t coord = xcb_query_pointer(dpy, root);
xcb_query_pointer_reply_t * poin = xcb_query_pointer_reply(dpy, coord, 0);
uint32_t val[2] = {1, 3};
if (values[2] == val[0]) {
if ((values[2] == val[0]) && (win != 0)) {
xcb_get_geometry_cookie_t geom_now = xcb_get_geometry(dpy, win);
xcb_get_geometry_reply_t * geom = xcb_get_geometry_reply(dpy, geom_now, NULL);
values[0] = ((poin->root_x + geom->width) > scre->width_in_pixels) ?
Expand All @@ -64,15 +66,15 @@ static void eventHandlerMotionNotify(xcb_generic_event_t * ev) {
(scre->height_in_pixels - geom->height) : poin->root_y;
xcb_configure_window(dpy, win, XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y, values);
} else if (values[2] == val[1]) {
}
if ((values[2] == val[1]) && (win != 0)) {
xcb_get_geometry_cookie_t geom_now = xcb_get_geometry(dpy, win);
xcb_get_geometry_reply_t* geom = xcb_get_geometry_reply(dpy, geom_now, NULL);
values[0] = poin->root_x - geom->x;
values[1] = poin->root_y - geom->y;
xcb_configure_window(dpy, win, XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT, values);
}
else {}
}

static xcb_keycode_t * xcb_get_keycodes(xcb_keysym_t keysym) {
Expand Down Expand Up @@ -102,6 +104,7 @@ static xcb_keysym_t xcb_get_keysym(xcb_keycode_t keycode) {
static void eventHandlerKeyPress(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);
win = e->child;
int key_table_size = sizeof(keys) / sizeof(*keys);
for (int i = 0; i < key_table_size; ++i) {
if ((keys[i].keysym == keysym) && (keys[i].mod == e->state)) {
Expand All @@ -110,6 +113,15 @@ static void eventHandlerKeyPress(xcb_generic_event_t * ev) {
}
}

static void eventHandlerEnterNotify(xcb_generic_event_t * ev) {
xcb_enter_notify_event_t * e = ( xcb_enter_notify_event_t *) ev;
xcb_drawable_t win_e = e->event;
if ((win_e != 0) && (win_e != root)) {
xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT, win_e,
XCB_CURRENT_TIME);
}
}

static void eventHandlerButtonRelease(xcb_generic_event_t * ev) {
xcb_ungrab_pointer(dpy, XCB_CURRENT_TIME);
}
Expand Down Expand Up @@ -169,7 +181,7 @@ static int die(char * errstr) {
int main(int argc, char * argv[]) {
int ret = 0;
if ((argc == 2) && (strcmp("-v", argv[1]) == 0)) {
ret = die("xwm-0.0.1, © 2020 Michael Czigler, see LICENSE for details\n");
ret = die("xwm-0.0.2, © 2020 Michael Czigler, see LICENSE for details\n");
}
if ((ret == 0) && (argc != 1)) {
ret = die("usage: xwm [-v]\n");
Expand Down
6 changes: 4 additions & 2 deletions xwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ static void closewm(char ** com);

/* event hander actions */
static int eventHandler(void);
static void eventHandlerButtonPress(xcb_generic_event_t * ev);
static void eventHandlerMotionNotify(xcb_generic_event_t * ev);
static void eventHandlerKeyPress(xcb_generic_event_t * ev);
static void eventHandlerEnterNotify(xcb_generic_event_t * ev);
static void eventHandlerButtonPress(xcb_generic_event_t * ev);
static void eventHandlerButtonRelease(xcb_generic_event_t * ev);
static void eventHandlerKeyPress(xcb_generic_event_t * ev);
static void eventHandlerDestroyNotify(xcb_generic_event_t * ev);
static handler_func_t handler_funs[] = {
{ XCB_MOTION_NOTIFY, eventHandlerMotionNotify },
{ XCB_ENTER_NOTIFY, eventHandlerEnterNotify },
{ XCB_BUTTON_PRESS, eventHandlerButtonPress },
{ XCB_BUTTON_RELEASE, eventHandlerButtonRelease },
{ XCB_KEY_PRESS, eventHandlerKeyPress },
Expand Down

0 comments on commit 265a5cb

Please sign in to comment.