diff options
author | Luminarys <kizunanohikari@gmail.com> | 2015-08-17 10:18:06 -0500 |
---|---|---|
committer | Luminarys <kizunanohikari@gmail.com> | 2015-08-17 10:18:06 -0500 |
commit | 47ec999e7184d29c2911af20ce696d1f4e948e29 (patch) | |
tree | 15e595e631b97210708ffae99684eb6e00a9c70c | |
parent | Deleted file (diff) | |
download | sway-47ec999e7184d29c2911af20ce696d1f4e948e29.tar.gz sway-47ec999e7184d29c2911af20ce696d1f4e948e29.tar.zst sway-47ec999e7184d29c2911af20ce696d1f4e948e29.zip |
Fixes to floating and umanaged views
-rw-r--r-- | include/container.h | 5 | ||||
-rw-r--r-- | sway/commands.c | 13 | ||||
-rw-r--r-- | sway/container.c | 35 | ||||
-rw-r--r-- | sway/handlers.c | 49 | ||||
-rw-r--r-- | sway/layout.c | 11 |
5 files changed, 99 insertions, 14 deletions
diff --git a/include/container.h b/include/container.h index 7560ddb8..3136e565 100644 --- a/include/container.h +++ b/include/container.h | |||
@@ -36,6 +36,9 @@ struct sway_container { | |||
36 | // Not including borders or margins | 36 | // Not including borders or margins |
37 | int width, height; | 37 | int width, height; |
38 | 38 | ||
39 | // Used for setting floating geometry | ||
40 | int desired_width, desired_height; | ||
41 | |||
39 | int x, y; | 42 | int x, y; |
40 | 43 | ||
41 | bool visible; | 44 | bool visible; |
@@ -62,6 +65,8 @@ swayc_t *new_workspace(swayc_t * output, const char *name); | |||
62 | swayc_t *new_container(swayc_t *child, enum swayc_layouts layout); | 65 | swayc_t *new_container(swayc_t *child, enum swayc_layouts layout); |
63 | //Creates view as a sibling of current focused container, or as child of a workspace | 66 | //Creates view as a sibling of current focused container, or as child of a workspace |
64 | swayc_t *new_view(swayc_t *sibling, wlc_handle handle); | 67 | swayc_t *new_view(swayc_t *sibling, wlc_handle handle); |
68 | //Creates view as a new floating view which is in the active workspace | ||
69 | swayc_t *new_floating_view(wlc_handle handle); | ||
65 | 70 | ||
66 | 71 | ||
67 | swayc_t *destroy_output(swayc_t *output); | 72 | swayc_t *destroy_output(swayc_t *output); |
diff --git a/sway/commands.c b/sway/commands.c index 91dfa2b2..8a81cd76 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -183,16 +183,19 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) { | |||
183 | view->is_floating = true; | 183 | view->is_floating = true; |
184 | for (i = 0; i < view->parent->children->length; i++) { | 184 | for (i = 0; i < view->parent->children->length; i++) { |
185 | if (view->parent->children->items[i] == view) { | 185 | if (view->parent->children->items[i] == view) { |
186 | // Cut down on width/height so it's obvious that you've gone floating | 186 | // Try to use desired geometry to set w/h |
187 | // if this is the only view | 187 | if (view->desired_width != -1) { |
188 | view->width = view->width - 30; | 188 | view->width = view->desired_width; |
189 | view->height = view->height - 30; | 189 | } |
190 | if (view->desired_height != -1) { | ||
191 | view->height = view->desired_height; | ||
192 | } | ||
190 | 193 | ||
191 | // Swap from the list of whatever container the view was in | 194 | // Swap from the list of whatever container the view was in |
192 | // to the workspace->floating list | 195 | // to the workspace->floating list |
193 | // TODO: Destroy any remaining empty containers | ||
194 | list_del(view->parent->children, i); | 196 | list_del(view->parent->children, i); |
195 | list_add(active_workspace->floating, view); | 197 | list_add(active_workspace->floating, view); |
198 | destroy_container(view->parent); | ||
196 | 199 | ||
197 | // Set the new position of the container and arrange windows | 200 | // Set the new position of the container and arrange windows |
198 | view->x = (active_workspace->width - view->width)/2; | 201 | view->x = (active_workspace->width - view->width)/2; |
diff --git a/sway/container.c b/sway/container.c index 87e48e91..1f93d4dc 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -135,6 +135,9 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { | |||
135 | view->name = strdup(title); | 135 | view->name = strdup(title); |
136 | view->visible = true; | 136 | view->visible = true; |
137 | 137 | ||
138 | view->desired_width = -1; | ||
139 | view->desired_height = -1; | ||
140 | |||
138 | // TODO: properly set this | 141 | // TODO: properly set this |
139 | view->is_floating = false; | 142 | view->is_floating = false; |
140 | 143 | ||
@@ -149,6 +152,38 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { | |||
149 | return view; | 152 | return view; |
150 | } | 153 | } |
151 | 154 | ||
155 | swayc_t *new_floating_view(wlc_handle handle) { | ||
156 | const char *title = wlc_view_get_title(handle); | ||
157 | swayc_t *view = new_swayc(C_VIEW); | ||
158 | sway_log(L_DEBUG, "Adding new view %u:%s as a floating view", | ||
159 | (unsigned int)handle, title); | ||
160 | //Setup values | ||
161 | view->handle = handle; | ||
162 | view->name = strdup(title); | ||
163 | view->visible = true; | ||
164 | |||
165 | // Set the geometry of the floating view | ||
166 | const struct wlc_geometry* geometry = wlc_view_get_geometry(handle); | ||
167 | |||
168 | view->x = geometry->origin.x; | ||
169 | view->y = geometry->origin.y; | ||
170 | view->width = geometry->size.w; | ||
171 | view->height = geometry->size.h; | ||
172 | |||
173 | view->desired_width = -1; | ||
174 | view->desired_height = -1; | ||
175 | |||
176 | view->is_floating = true; | ||
177 | |||
178 | //Case of focused workspace, just create as child of it | ||
179 | list_add(active_workspace->floating, view); | ||
180 | view->parent = active_workspace; | ||
181 | if (active_workspace->focused == NULL) { | ||
182 | active_workspace->focused = view; | ||
183 | } | ||
184 | return view; | ||
185 | } | ||
186 | |||
152 | 187 | ||
153 | swayc_t *destroy_output(swayc_t *output) { | 188 | swayc_t *destroy_output(swayc_t *output) { |
154 | if (output->children->length == 0) { | 189 | if (output->children->length == 0) { |
diff --git a/sway/handlers.c b/sway/handlers.c index 3e83b850..85df09f7 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include "handlers.h" | 10 | #include "handlers.h" |
11 | #include "stringop.h" | 11 | #include "stringop.h" |
12 | #include "workspace.h" | 12 | #include "workspace.h" |
13 | #include "container.h" | ||
13 | 14 | ||
14 | static struct wlc_origin mouse_origin; | 15 | static struct wlc_origin mouse_origin; |
15 | 16 | ||
@@ -88,17 +89,24 @@ static void handle_output_focused(wlc_handle output, bool focus) { | |||
88 | static bool handle_view_created(wlc_handle handle) { | 89 | static bool handle_view_created(wlc_handle handle) { |
89 | swayc_t *focused = get_focused_container(&root_container); | 90 | swayc_t *focused = get_focused_container(&root_container); |
90 | uint32_t type = wlc_view_get_type(handle); | 91 | uint32_t type = wlc_view_get_type(handle); |
91 | //If override_redirect/unmanaged/popup/modal/splach | 92 | // If override_redirect/unmanaged/popup/modal/splach |
92 | if (type) { | 93 | if (type) { |
93 | sway_log(L_DEBUG,"Unmanaged window of type %x left alone", type); | 94 | sway_log(L_DEBUG,"Unmanaged window of type %x left alone", type); |
94 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); | 95 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); |
95 | if (type & WLC_BIT_UNMANAGED) { | 96 | if (type & WLC_BIT_UNMANAGED) { |
96 | return true; | 97 | return true; |
97 | } | 98 | } |
98 | //for things like Dmenu | 99 | // For things like Dmenu |
99 | if (type & WLC_BIT_OVERRIDE_REDIRECT) { | 100 | if (type & WLC_BIT_OVERRIDE_REDIRECT) { |
100 | wlc_view_focus(handle); | 101 | wlc_view_focus(handle); |
101 | } | 102 | } |
103 | |||
104 | // Float popups | ||
105 | if (type & WLC_BIT_POPUP) { | ||
106 | swayc_t *view = new_floating_view(handle); | ||
107 | focus_view(view); | ||
108 | arrange_windows(active_workspace, -1, -1); | ||
109 | } | ||
102 | } else { | 110 | } else { |
103 | swayc_t *view = new_view(focused, handle); | 111 | swayc_t *view = new_view(focused, handle); |
104 | //Set maximize flag for windows. | 112 | //Set maximize flag for windows. |
@@ -118,6 +126,24 @@ static bool handle_view_created(wlc_handle handle) { | |||
118 | 126 | ||
119 | static void handle_view_destroyed(wlc_handle handle) { | 127 | static void handle_view_destroyed(wlc_handle handle) { |
120 | sway_log(L_DEBUG, "Destroying window %u", (unsigned int)handle); | 128 | sway_log(L_DEBUG, "Destroying window %u", (unsigned int)handle); |
129 | |||
130 | // Properly handle unmanaged views | ||
131 | uint32_t type = wlc_view_get_type(handle); | ||
132 | if (type) { | ||
133 | wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); | ||
134 | sway_log(L_DEBUG,"Unmanaged window of type %x was destroyed", type); | ||
135 | if (type & WLC_BIT_UNMANAGED) { | ||
136 | focus_view(focus_pointer()); | ||
137 | arrange_windows(active_workspace, -1, -1); | ||
138 | return; | ||
139 | } | ||
140 | |||
141 | if (type & WLC_BIT_OVERRIDE_REDIRECT) { | ||
142 | focus_view(focus_pointer()); | ||
143 | arrange_windows(active_workspace, -1, -1); | ||
144 | return; | ||
145 | } | ||
146 | } | ||
121 | swayc_t *view = get_swayc_for_handle(handle, &root_container); | 147 | swayc_t *view = get_swayc_for_handle(handle, &root_container); |
122 | swayc_t *parent; | 148 | swayc_t *parent; |
123 | swayc_t *focused = get_focused_container(&root_container); | 149 | swayc_t *focused = get_focused_container(&root_container); |
@@ -135,8 +161,23 @@ static void handle_view_focus(wlc_handle view, bool focus) { | |||
135 | return; | 161 | return; |
136 | } | 162 | } |
137 | 163 | ||
138 | static void handle_view_geometry_request(wlc_handle view, const struct wlc_geometry* geometry) { | 164 | static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geometry* geometry) { |
139 | // deny that shit | 165 | // If the view is floating, then apply the geometry. |
166 | // Otherwise save the desired width/height for the view. | ||
167 | // This will not do anything for the time being as WLC improperly sends geometry requests | ||
168 | swayc_t *view = get_swayc_for_handle(handle, &root_container); | ||
169 | if (view) { | ||
170 | if (view->is_floating) { | ||
171 | view->width = geometry->size.w; | ||
172 | view->height = geometry->size.h; | ||
173 | view->x = geometry->origin.x; | ||
174 | view->y = geometry->origin.y; | ||
175 | arrange_windows(view->parent, -1, -1); | ||
176 | } else { | ||
177 | view->desired_width = geometry->size.w; | ||
178 | view->desired_height = geometry->size.h; | ||
179 | } | ||
180 | } | ||
140 | } | 181 | } |
141 | 182 | ||
142 | static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit state, bool toggle) { | 183 | static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit state, bool toggle) { |
diff --git a/sway/layout.c b/sway/layout.c index c53b9dad..1bc65050 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -73,11 +73,12 @@ swayc_t *remove_child(swayc_t *parent, swayc_t *child) { | |||
73 | break; | 73 | break; |
74 | } | 74 | } |
75 | } | 75 | } |
76 | } | 76 | } else { |
77 | for (i = 0; i < parent->children->length; ++i) { | 77 | for (i = 0; i < parent->children->length; ++i) { |
78 | if (parent->children->items[i] == child) { | 78 | if (parent->children->items[i] == child) { |
79 | list_del(parent->children, i); | 79 | list_del(parent->children, i); |
80 | break; | 80 | break; |
81 | } | ||
81 | } | 82 | } |
82 | } | 83 | } |
83 | if (parent->focused == child) { | 84 | if (parent->focused == child) { |