summaryrefslogtreecommitdiffstats
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) {
452 wlc_view_focus(handle); 452 wlc_view_focus(handle);
453 wlc_view_bring_to_front(handle); 453 wlc_view_bring_to_front(handle);
454 newview = new_floating_view(handle); 454 newview = new_floating_view(handle);
455 /* fallthrough */
455 case WLC_BIT_POPUP: 456 case WLC_BIT_POPUP:
456 wlc_view_bring_to_front(handle); 457 wlc_view_bring_to_front(handle);
457 break; 458 break;
@@ -552,21 +553,24 @@ static void handle_view_destroyed(wlc_handle handle) {
552 bool fullscreen = swayc_is_fullscreen(view); 553 bool fullscreen = swayc_is_fullscreen(view);
553 remove_view_from_scratchpad(view); 554 remove_view_from_scratchpad(view);
554 swayc_t *parent = destroy_view(view); 555 swayc_t *parent = destroy_view(view);
555 if (fullscreen) { 556 if (parent) {
556 parent->fullscreen = NULL; 557 if (fullscreen) {
557 } 558 parent->fullscreen = NULL;
559 }
558 560
559 // Destroy empty workspaces 561 ipc_event_window(parent, "close");
560 if (parent->type == C_WORKSPACE &&
561 parent->children->length == 0 &&
562 parent->floating->length == 0 &&
563 swayc_active_workspace() != parent &&
564 !parent->visible) {
565 parent = destroy_workspace(parent);
566 }
567 562
568 arrange_windows(parent, -1, -1); 563 // Destroy empty workspaces
569 ipc_event_window(parent, "close"); 564 if (parent->type == C_WORKSPACE &&
565 parent->children->length == 0 &&
566 parent->floating->length == 0 &&
567 swayc_active_workspace() != parent &&
568 !parent->visible) {
569 parent = destroy_workspace(parent);
570 }
571
572 arrange_windows(parent, -1, -1);
573 }
570 } else { 574 } else {
571 // Is it unmanaged? 575 // Is it unmanaged?
572 int i; 576 int i;
@@ -582,6 +586,15 @@ static void handle_view_destroyed(wlc_handle handle) {
582 } 586 }
583 } 587 }
584 } 588 }
589 // Is it in the scratchpad?
590 for (i = 0; i < scratchpad->length; ++i) {
591 swayc_t *item = scratchpad->items[i];
592 if (item->handle == handle) {
593 list_del(scratchpad, i);
594 destroy_view(item);
595 break;
596 }
597 }
585 } 598 }
586 set_focused_container(get_focused_view(&root_container)); 599 set_focused_container(get_focused_view(&root_container));
587} 600}
@@ -805,11 +818,11 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
805 struct sway_binding *binding = mode->bindings->items[i]; 818 struct sway_binding *binding = mode->bindings->items[i];
806 if ((modifiers->mods ^ binding->modifiers) == 0) { 819 if ((modifiers->mods ^ binding->modifiers) == 0) {
807 switch (state) { 820 switch (state) {
808 case WLC_KEY_STATE_PRESSED: { 821 case WLC_KEY_STATE_PRESSED:
809 if (!binding->release && valid_bindsym(binding)) { 822 if (!binding->release && valid_bindsym(binding)) {
810 list_add(candidates, binding); 823 list_add(candidates, binding);
811 } 824 }
812 } 825 break;
813 case WLC_KEY_STATE_RELEASED: 826 case WLC_KEY_STATE_RELEASED:
814 if (binding->release && handle_bindsym_release(binding)) { 827 if (binding->release && handle_bindsym_release(binding)) {
815 list_free(candidates); 828 list_free(candidates);
@@ -842,12 +855,13 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
842 return EVENT_PASSTHROUGH; 855 return EVENT_PASSTHROUGH;
843} 856}
844 857
845static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_point *origin) { 858static bool handle_pointer_motion(wlc_handle handle, uint32_t time, double x, double y) {
846 if (desktop_shell.is_locked) { 859 if (desktop_shell.is_locked) {
847 return EVENT_PASSTHROUGH; 860 return EVENT_PASSTHROUGH;
848 } 861 }
849 862
850 struct wlc_point new_origin = *origin; 863 double new_x = x;
864 double new_y = y;
851 // Switch to adjacent output if touching output edge. 865 // Switch to adjacent output if touching output edge.
852 // 866 //
853 // Since this doesn't currently support moving windows between outputs we 867 // 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
856 !pointer_state.left.held && !pointer_state.right.held && !pointer_state.scroll.held) { 870 !pointer_state.left.held && !pointer_state.right.held && !pointer_state.scroll.held) {
857 871
858 swayc_t *output = swayc_active_output(), *adjacent = NULL; 872 swayc_t *output = swayc_active_output(), *adjacent = NULL;
859 struct wlc_point abs_pos = *origin; 873 struct wlc_point abs_pos = { .x = x + output->x, .y = y + output->y };
860 abs_pos.x += output->x; 874 if (x <= 0) { // Left edge
861 abs_pos.y += output->y;
862 if (origin->x == 0) { // Left edge
863 if ((adjacent = swayc_adjacent_output(output, MOVE_LEFT, &abs_pos, false))) { 875 if ((adjacent = swayc_adjacent_output(output, MOVE_LEFT, &abs_pos, false))) {
864 if (workspace_switch(swayc_active_workspace_for(adjacent))) { 876 if (workspace_switch(swayc_active_workspace_for(adjacent))) {
865 new_origin.x = adjacent->width; 877 new_x = adjacent->width;
866 // adjust for differently aligned outputs (well, this is 878 // adjust for differently aligned outputs (well, this is
867 // only correct when the two outputs have the same 879 // only correct when the two outputs have the same
868 // resolution or the same dpi I guess, it should take 880 // resolution or the same dpi I guess, it should take
869 // physical attributes into account) 881 // physical attributes into account)
870 new_origin.y += (output->y - adjacent->y); 882 new_y += (output->y - adjacent->y);
871 } 883 }
872 } 884 }
873 } else if ((double)origin->x == output->width) { // Right edge 885 } else if (x >= output->width) { // Right edge
874 if ((adjacent = swayc_adjacent_output(output, MOVE_RIGHT, &abs_pos, false))) { 886 if ((adjacent = swayc_adjacent_output(output, MOVE_RIGHT, &abs_pos, false))) {
875 if (workspace_switch(swayc_active_workspace_for(adjacent))) { 887 if (workspace_switch(swayc_active_workspace_for(adjacent))) {
876 new_origin.x = 0; 888 new_x = 0;
877 new_origin.y += (output->y - adjacent->y); 889 new_y += (output->y - adjacent->y);
878 } 890 }
879 } 891 }
880 } else if (origin->y == 0) { // Top edge 892 } else if (y <= 0) { // Top edge
881 if ((adjacent = swayc_adjacent_output(output, MOVE_UP, &abs_pos, false))) { 893 if ((adjacent = swayc_adjacent_output(output, MOVE_UP, &abs_pos, false))) {
882 if (workspace_switch(swayc_active_workspace_for(adjacent))) { 894 if (workspace_switch(swayc_active_workspace_for(adjacent))) {
883 new_origin.y = adjacent->height; 895 new_y = adjacent->height;
884 new_origin.x += (output->x - adjacent->x); 896 new_x += (output->x - adjacent->x);
885 } 897 }
886 } 898 }
887 } else if ((double)origin->y == output->height) { // Bottom edge 899 } else if (y >= output->height) { // Bottom edge
888 if ((adjacent = swayc_adjacent_output(output, MOVE_DOWN, &abs_pos, false))) { 900 if ((adjacent = swayc_adjacent_output(output, MOVE_DOWN, &abs_pos, false))) {
889 if (workspace_switch(swayc_active_workspace_for(adjacent))) { 901 if (workspace_switch(swayc_active_workspace_for(adjacent))) {
890 new_origin.y = 0; 902 new_y = 0;
891 new_origin.x += (output->x - adjacent->x); 903 new_x += (output->x - adjacent->x);
892 } 904 }
893 } 905 }
894 } 906 }
895 } 907 }
896 908
897 pointer_position_set(&new_origin, false); 909 pointer_position_set(new_x, new_y, false);
898 910
899 swayc_t *focused = get_focused_container(&root_container); 911 swayc_t *focused = get_focused_container(&root_container);
900 if (focused->type == C_VIEW) { 912 if (focused->type == C_VIEW) {
@@ -935,15 +947,15 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
935 struct sway_binding *binding = mode->bindings->items[i]; 947 struct sway_binding *binding = mode->bindings->items[i];
936 if ((modifiers->mods ^ binding->modifiers) == 0) { 948 if ((modifiers->mods ^ binding->modifiers) == 0) {
937 switch (state) { 949 switch (state) {
938 case WLC_BUTTON_STATE_PRESSED: { 950 case WLC_BUTTON_STATE_PRESSED:
939 if (!binding->release && handle_bindsym(binding, button, 0)) { 951 if (!binding->release && handle_bindsym(binding, button, 0)) {
940 return EVENT_HANDLED; 952 return EVENT_HANDLED;
941 } 953 }
954 break;
955 case WLC_BUTTON_STATE_RELEASED:
956 if (binding->release && handle_bindsym(binding, button, 0)) {
957 return EVENT_HANDLED;
942 } 958 }
943 case WLC_BUTTON_STATE_RELEASED:
944 if (binding->release && handle_bindsym(binding, button, 0)) {
945 return EVENT_HANDLED;
946 }
947 break; 959 break;
948 } 960 }
949 } 961 }
@@ -1084,16 +1096,8 @@ bool handle_pointer_scroll(wlc_handle view, uint32_t time, const struct wlc_modi
1084 return EVENT_PASSTHROUGH; 1096 return EVENT_PASSTHROUGH;
1085} 1097}
1086 1098
1087static void clip_test_cb(void *data, const char *type, int fd) {
1088 const char *str = data;
1089 write(fd, str, strlen(str));
1090 close(fd);
1091}
1092
1093static void handle_wlc_ready(void) { 1099static void handle_wlc_ready(void) {
1094 sway_log(L_DEBUG, "Compositor is ready, executing cmds in queue"); 1100 sway_log(L_DEBUG, "Compositor is ready, executing cmds in queue");
1095 const char *type = "text/plain;charset=utf-8";
1096 wlc_set_selection("test", &type, 1, &clip_test_cb);
1097 // Execute commands until there are none left 1101 // Execute commands until there are none left
1098 config->active = true; 1102 config->active = true;
1099 while (config->cmd_queue->length) { 1103 while (config->cmd_queue->length) {
@@ -1122,7 +1126,7 @@ void register_wlc_handlers() {
1122 wlc_set_view_request_state_cb(handle_view_state_request); 1126 wlc_set_view_request_state_cb(handle_view_state_request);
1123 wlc_set_view_properties_updated_cb(handle_view_properties_updated); 1127 wlc_set_view_properties_updated_cb(handle_view_properties_updated);
1124 wlc_set_keyboard_key_cb(handle_key); 1128 wlc_set_keyboard_key_cb(handle_key);
1125 wlc_set_pointer_motion_cb(handle_pointer_motion); 1129 wlc_set_pointer_motion_cb_v2(handle_pointer_motion);
1126 wlc_set_pointer_button_cb(handle_pointer_button); 1130 wlc_set_pointer_button_cb(handle_pointer_button);
1127 wlc_set_pointer_scroll_cb(handle_pointer_scroll); 1131 wlc_set_pointer_scroll_cb(handle_pointer_scroll);
1128 wlc_set_compositor_ready_cb(handle_wlc_ready); 1132 wlc_set_compositor_ready_cb(handle_wlc_ready);