aboutsummaryrefslogtreecommitdiff
path: root/sway/handlers.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/handlers.c')
-rw-r--r--sway/handlers.c104
1 files changed, 54 insertions, 50 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
index 052789ca..d37142a9 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -452,6 +452,7 @@ static bool handle_view_created(wlc_handle handle) {
wlc_view_focus(handle);
wlc_view_bring_to_front(handle);
newview = new_floating_view(handle);
+ /* fallthrough */
case WLC_BIT_POPUP:
wlc_view_bring_to_front(handle);
break;
@@ -552,21 +553,24 @@ static void handle_view_destroyed(wlc_handle handle) {
bool fullscreen = swayc_is_fullscreen(view);
remove_view_from_scratchpad(view);
swayc_t *parent = destroy_view(view);
- if (fullscreen) {
- parent->fullscreen = NULL;
- }
+ if (parent) {
+ if (fullscreen) {
+ parent->fullscreen = NULL;
+ }
- // Destroy empty workspaces
- if (parent->type == C_WORKSPACE &&
- parent->children->length == 0 &&
- parent->floating->length == 0 &&
- swayc_active_workspace() != parent &&
- !parent->visible) {
- parent = destroy_workspace(parent);
- }
+ ipc_event_window(parent, "close");
- arrange_windows(parent, -1, -1);
- ipc_event_window(parent, "close");
+ // Destroy empty workspaces
+ if (parent->type == C_WORKSPACE &&
+ parent->children->length == 0 &&
+ parent->floating->length == 0 &&
+ swayc_active_workspace() != parent &&
+ !parent->visible) {
+ parent = destroy_workspace(parent);
+ }
+
+ arrange_windows(parent, -1, -1);
+ }
} else {
// Is it unmanaged?
int i;
@@ -582,6 +586,15 @@ static void handle_view_destroyed(wlc_handle handle) {
}
}
}
+ // Is it in the scratchpad?
+ for (i = 0; i < scratchpad->length; ++i) {
+ swayc_t *item = scratchpad->items[i];
+ if (item->handle == handle) {
+ list_del(scratchpad, i);
+ destroy_view(item);
+ break;
+ }
+ }
}
set_focused_container(get_focused_view(&root_container));
}
@@ -805,11 +818,11 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
struct sway_binding *binding = mode->bindings->items[i];
if ((modifiers->mods ^ binding->modifiers) == 0) {
switch (state) {
- case WLC_KEY_STATE_PRESSED: {
+ case WLC_KEY_STATE_PRESSED:
if (!binding->release && valid_bindsym(binding)) {
list_add(candidates, binding);
}
- }
+ break;
case WLC_KEY_STATE_RELEASED:
if (binding->release && handle_bindsym_release(binding)) {
list_free(candidates);
@@ -842,12 +855,13 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
return EVENT_PASSTHROUGH;
}
-static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_point *origin) {
+static bool handle_pointer_motion(wlc_handle handle, uint32_t time, double x, double y) {
if (desktop_shell.is_locked) {
return EVENT_PASSTHROUGH;
}
- struct wlc_point new_origin = *origin;
+ double new_x = x;
+ double new_y = y;
// Switch to adjacent output if touching output edge.
//
// Since this doesn't currently support moving windows between outputs we
@@ -856,45 +870,43 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
!pointer_state.left.held && !pointer_state.right.held && !pointer_state.scroll.held) {
swayc_t *output = swayc_active_output(), *adjacent = NULL;
- struct wlc_point abs_pos = *origin;
- abs_pos.x += output->x;
- abs_pos.y += output->y;
- if (origin->x == 0) { // Left edge
+ struct wlc_point abs_pos = { .x = x + output->x, .y = y + output->y };
+ if (x <= 0) { // Left edge
if ((adjacent = swayc_adjacent_output(output, MOVE_LEFT, &abs_pos, false))) {
if (workspace_switch(swayc_active_workspace_for(adjacent))) {
- new_origin.x = adjacent->width;
+ new_x = adjacent->width;
// adjust for differently aligned outputs (well, this is
// only correct when the two outputs have the same
// resolution or the same dpi I guess, it should take
// physical attributes into account)
- new_origin.y += (output->y - adjacent->y);
+ new_y += (output->y - adjacent->y);
}
}
- } else if ((double)origin->x == output->width) { // Right edge
+ } else if (x >= output->width) { // Right edge
if ((adjacent = swayc_adjacent_output(output, MOVE_RIGHT, &abs_pos, false))) {
if (workspace_switch(swayc_active_workspace_for(adjacent))) {
- new_origin.x = 0;
- new_origin.y += (output->y - adjacent->y);
+ new_x = 0;
+ new_y += (output->y - adjacent->y);
}
}
- } else if (origin->y == 0) { // Top edge
+ } else if (y <= 0) { // Top edge
if ((adjacent = swayc_adjacent_output(output, MOVE_UP, &abs_pos, false))) {
if (workspace_switch(swayc_active_workspace_for(adjacent))) {
- new_origin.y = adjacent->height;
- new_origin.x += (output->x - adjacent->x);
+ new_y = adjacent->height;
+ new_x += (output->x - adjacent->x);
}
}
- } else if ((double)origin->y == output->height) { // Bottom edge
+ } else if (y >= output->height) { // Bottom edge
if ((adjacent = swayc_adjacent_output(output, MOVE_DOWN, &abs_pos, false))) {
if (workspace_switch(swayc_active_workspace_for(adjacent))) {
- new_origin.y = 0;
- new_origin.x += (output->x - adjacent->x);
+ new_y = 0;
+ new_x += (output->x - adjacent->x);
}
}
}
}
- pointer_position_set(&new_origin, false);
+ pointer_position_set(new_x, new_y, false);
swayc_t *focused = get_focused_container(&root_container);
if (focused->type == C_VIEW) {
@@ -935,15 +947,15 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
struct sway_binding *binding = mode->bindings->items[i];
if ((modifiers->mods ^ binding->modifiers) == 0) {
switch (state) {
- case WLC_BUTTON_STATE_PRESSED: {
- if (!binding->release && handle_bindsym(binding, button, 0)) {
- return EVENT_HANDLED;
- }
+ case WLC_BUTTON_STATE_PRESSED:
+ if (!binding->release && handle_bindsym(binding, button, 0)) {
+ return EVENT_HANDLED;
+ }
+ break;
+ case WLC_BUTTON_STATE_RELEASED:
+ if (binding->release && handle_bindsym(binding, button, 0)) {
+ return EVENT_HANDLED;
}
- case WLC_BUTTON_STATE_RELEASED:
- if (binding->release && handle_bindsym(binding, button, 0)) {
- return EVENT_HANDLED;
- }
break;
}
}
@@ -1084,16 +1096,8 @@ bool handle_pointer_scroll(wlc_handle view, uint32_t time, const struct wlc_modi
return EVENT_PASSTHROUGH;
}
-static void clip_test_cb(void *data, const char *type, int fd) {
- const char *str = data;
- write(fd, str, strlen(str));
- close(fd);
-}
-
static void handle_wlc_ready(void) {
sway_log(L_DEBUG, "Compositor is ready, executing cmds in queue");
- const char *type = "text/plain;charset=utf-8";
- wlc_set_selection("test", &type, 1, &clip_test_cb);
// Execute commands until there are none left
config->active = true;
while (config->cmd_queue->length) {
@@ -1122,7 +1126,7 @@ void register_wlc_handlers() {
wlc_set_view_request_state_cb(handle_view_state_request);
wlc_set_view_properties_updated_cb(handle_view_properties_updated);
wlc_set_keyboard_key_cb(handle_key);
- wlc_set_pointer_motion_cb(handle_pointer_motion);
+ wlc_set_pointer_motion_cb_v2(handle_pointer_motion);
wlc_set_pointer_button_cb(handle_pointer_button);
wlc_set_pointer_scroll_cb(handle_pointer_scroll);
wlc_set_compositor_ready_cb(handle_wlc_ready);