Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added _NET_WM_MOVERESIZE handling for the move case #1183

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
48 changes: 48 additions & 0 deletions src/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,59 @@ 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) {
if (allow_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 XCB_EWMH_WM_MOVERESIZE_MOVE:
wm_move_node(e, loc);
break;
case XCB_EWMH_WM_MOVERESIZE_SIZE_TOPLEFT ... XCB_EWMH_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
4 changes: 4 additions & 0 deletions src/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <xcb/xcb.h>
#include <xcb/xcb_event.h>
#include <xcb/xcb_ewmh.h>

#define ERROR_CODE_BAD_WINDOW 3

Expand All @@ -41,6 +42,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 Down
2 changes: 2 additions & 0 deletions src/messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,7 @@ void set_setting(coordinates_t loc, char *name, char *value, FILE *rsp)
SET_BOOL(center_pseudo_tiled)
SET_BOOL(honor_size_hints)
SET_BOOL(removal_adjustment)
SET_BOOL(allow_net_wm_moveresize)
#undef SET_BOOL
#define SET_MON_BOOL(s) \
} else if (streq(#s, name)) { \
Expand Down Expand Up @@ -1844,6 +1845,7 @@ void get_setting(coordinates_t loc, char *name, FILE* rsp)
GET_BOOL(remove_disabled_monitors)
GET_BOOL(remove_unplugged_monitors)
GET_BOOL(merge_overlapping_monitors)
GET_BOOL(allow_net_wm_moveresize)
#undef GET_BOOL
} else {
fail(rsp, "config: Unknown setting: '%s'.\n", name);
Expand Down
4 changes: 4 additions & 0 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ bool remove_disabled_monitors;
bool remove_unplugged_monitors;
bool merge_overlapping_monitors;

bool allow_net_wm_moveresize;

void run_config(int run_level)
{
if (fork() == 0) {
Expand Down Expand Up @@ -133,4 +135,6 @@ void load_settings(void)
remove_disabled_monitors = REMOVE_DISABLED_MONITORS;
remove_unplugged_monitors = REMOVE_UNPLUGGED_MONITORS;
merge_overlapping_monitors = MERGE_OVERLAPPING_MONITORS;

allow_net_wm_moveresize = ALLOW_NET_WM_MOVERESIZE;
}
4 changes: 4 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
#define REMOVE_UNPLUGGED_MONITORS false
#define MERGE_OVERLAPPING_MONITORS false

#define ALLOW_NET_WM_MOVERESIZE true

extern char external_rules_command[MAXLEN];
extern char status_prefix[MAXLEN];

Expand Down Expand Up @@ -111,6 +113,8 @@ extern bool remove_disabled_monitors;
extern bool remove_unplugged_monitors;
extern bool merge_overlapping_monitors;

extern bool allow_net_wm_moveresize;

void run_config(int run_level);
void load_settings(void);

Expand Down