Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bspwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ void setup(void)
ewmh->_NET_CLOSE_WINDOW,
ewmh->_NET_WM_STRUT_PARTIAL,
ewmh->_NET_WM_DESKTOP,
ewmh->_NET_WM_MOVERESIZE,
ewmh->_NET_WM_STATE,
ewmh->_NET_WM_STATE_HIDDEN,
ewmh->_NET_WM_STATE_FULLSCREEN,
Expand Down
46 changes: 46 additions & 0 deletions src/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,57 @@ void client_message(xcb_generic_event_t *evt)
if (ewmh_locate_desktop(e->data.data32[0], &dloc)) {
transfer_node(loc.monitor, loc.desktop, loc.node, dloc.monitor, dloc.desktop, dloc.desktop->focus, false);
}
} else if (e->type == ewmh->_NET_WM_MOVERESIZE) {
wm_move_resize_node(e, loc);
} else if (e->type == ewmh->_NET_CLOSE_WINDOW) {
close_node(loc.node);
}
}

void wm_move_resize_node(xcb_client_message_event_t* e, coordinates_t loc) {
uint32_t direction = e->data.data32[2];

switch (direction) {
case _NET_WM_MOVERESIZE_MOVE:
wm_move_node(e, loc);
break;
case _NET_WM_MOVERESIZE_SIZE_TOPLEFT ... _NET_WM_MOVERESIZE_SIZE_LEFT:
wm_resize_node(e, loc);
break;
default:
break;
}
}

void wm_move_node(xcb_client_message_event_t* e, coordinates_t loc) {
// This logic comes from pointer.c function grab_pointer,
// we have that logic for the pac == ACTION_MOVE branches taken.

xcb_window_t win = e->window;
xcb_point_t pos;

query_pointer(&win, &pos);

xcb_grab_pointer_reply_t *reply = xcb_grab_pointer_reply(dpy, xcb_grab_pointer(dpy, 0, root, XCB_EVENT_MASK_BUTTON_RELEASE|XCB_EVENT_MASK_BUTTON_MOTION, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, XCB_CURRENT_TIME), NULL);

if (reply == NULL || reply->status != XCB_GRAB_STATUS_SUCCESS) {
free(reply);
return;
}
free(reply);

put_status(SBSC_MASK_POINTER_ACTION, "pointer_action 0x%08X 0x%08X 0x%08X move begin\n", loc.monitor->id, loc.desktop->id, loc.node->id);

track_pointer(loc, ACTION_MOVE, pos);

}

void wm_resize_node(xcb_client_message_event_t* e, coordinates_t loc) {
// TODO resize window keeping the opposite 1 or 2 edges fixed
// Not sure if this is even possible as most tiling windows do not
// draw decorations with which the user could grab window edges.
}

void focus_in(xcb_generic_event_t *evt)
{
xcb_focus_in_event_t *e = (xcb_focus_in_event_t *) evt;
Expand Down
18 changes: 18 additions & 0 deletions src/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ void destroy_notify(xcb_generic_event_t *evt);
void unmap_notify(xcb_generic_event_t *evt);
void property_notify(xcb_generic_event_t *evt);
void client_message(xcb_generic_event_t *evt);
void wm_move_resize_node(xcb_client_message_event_t* e, coordinates_t loc);
void wm_move_node(xcb_client_message_event_t* e, coordinates_t loc);
void wm_resize_node(xcb_client_message_event_t* e, coordinates_t loc);
void focus_in(xcb_generic_event_t *evt);
void button_press(xcb_generic_event_t *evt);
void enter_notify(xcb_generic_event_t *evt);
Expand All @@ -49,4 +52,19 @@ void handle_state(monitor_t *m, desktop_t *d, node_t *n, xcb_atom_t state, unsig
void mapping_notify(xcb_generic_event_t *evt);
void process_error(xcb_generic_event_t *evt);

// These are used when handling client movement requests;
// they are directly from https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html#idm46035372579808
#define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
#define _NET_WM_MOVERESIZE_SIZE_TOP 1
#define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
#define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
#define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
#define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
#define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
#define _NET_WM_MOVERESIZE_SIZE_LEFT 7
#define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
#define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
#define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
#define _NET_WM_MOVERESIZE_CANCEL 11 /* cancel operation */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These constants are already defined in xcb_ewmh.h.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I updated the changes in d7a31ad. I don't know if github can do a PR as a squashed merge but I'm fine re-committing the 3 changes as 1 because it makes the history cleaner.


#endif