aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar taiyu <taiyu.len@gmail.com>2015-08-18 01:07:12 -0700
committerLibravatar taiyu <taiyu.len@gmail.com>2015-08-18 01:07:12 -0700
commit4606fb1ee3102dcaeab005d64eeead5842a5cd3e (patch)
treebca27e2363a8c6e4a51dc8f19d48ca95c699a987
parentstyle (diff)
parentAdded in basic, but semi-broken moving/resizing functionality to floating win... (diff)
downloadsway-4606fb1ee3102dcaeab005d64eeead5842a5cd3e.tar.gz
sway-4606fb1ee3102dcaeab005d64eeead5842a5cd3e.tar.zst
sway-4606fb1ee3102dcaeab005d64eeead5842a5cd3e.zip
merged Luminarys resizing code
-rw-r--r--include/config.h2
-rw-r--r--include/handlers.h2
-rw-r--r--sway/commands.c13
-rw-r--r--sway/handlers.c135
4 files changed, 138 insertions, 14 deletions
diff --git a/include/config.h b/include/config.h
index 38e93eb8..b9511aac 100644
--- a/include/config.h
+++ b/include/config.h
@@ -3,6 +3,7 @@
3 3
4#include <stdint.h> 4#include <stdint.h>
5#include <wlc/wlc.h> 5#include <wlc/wlc.h>
6#include <xkbcommon/xkbcommon.h>
6#include "list.h" 7#include "list.h"
7 8
8struct sway_variable { 9struct sway_variable {
@@ -32,6 +33,7 @@ struct sway_config {
32 list_t *cmd_queue; 33 list_t *cmd_queue;
33 list_t *workspace_outputs; 34 list_t *workspace_outputs;
34 struct sway_mode *current_mode; 35 struct sway_mode *current_mode;
36 uint32_t floating_mod;
35 37
36 // Flags 38 // Flags
37 bool focus_follows_mouse; 39 bool focus_follows_mouse;
diff --git a/include/handlers.h b/include/handlers.h
index 6ea4bbf1..6b642419 100644
--- a/include/handlers.h
+++ b/include/handlers.h
@@ -5,7 +5,9 @@
5#include <wlc/wlc.h> 5#include <wlc/wlc.h>
6 6
7extern struct wlc_interface interface; 7extern struct wlc_interface interface;
8extern uint32_t keys_pressed[32];
8 9
10//set focus to current pointer location and return focused container
9swayc_t *container_under_pointer(void); 11swayc_t *container_under_pointer(void);
10 12
11#endif 13#endif
diff --git a/sway/commands.c b/sway/commands.c
index 134593c7..548cb8ed 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -171,6 +171,10 @@ static bool cmd_exit(struct sway_config *config, int argc, char **argv) {
171} 171}
172 172
173static bool cmd_floating(struct sway_config *config, int argc, char **argv) { 173static bool cmd_floating(struct sway_config *config, int argc, char **argv) {
174 if (!checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1)) {
175 return false;
176 }
177
174 if (strcasecmp(argv[0], "toggle") == 0) { 178 if (strcasecmp(argv[0], "toggle") == 0) {
175 swayc_t *view = get_focused_container(&root_container); 179 swayc_t *view = get_focused_container(&root_container);
176 // Prevent running floating commands on things like workspaces 180 // Prevent running floating commands on things like workspaces
@@ -242,6 +246,14 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) {
242 return true; 246 return true;
243} 247}
244 248
249static bool cmd_floating_mod(struct sway_config *config, int argc, char **argv) {
250 if (!checkarg(argc, "floating_modifier", EXPECTED_EQUAL_TO, 1)) {
251 return false;
252 }
253 config->floating_mod = xkb_keysym_from_name(argv[0], XKB_KEYSYM_CASE_INSENSITIVE);
254 return true;
255}
256
245static bool cmd_focus(struct sway_config *config, int argc, char **argv) { 257static bool cmd_focus(struct sway_config *config, int argc, char **argv) {
246 if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) { 258 if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) {
247 return false; 259 return false;
@@ -466,6 +478,7 @@ static struct cmd_handler handlers[] = {
466 { "exec_always", cmd_exec_always }, 478 { "exec_always", cmd_exec_always },
467 { "exit", cmd_exit }, 479 { "exit", cmd_exit },
468 { "floating", cmd_floating }, 480 { "floating", cmd_floating },
481 { "floating_modifier", cmd_floating_mod },
469 { "focus", cmd_focus }, 482 { "focus", cmd_focus },
470 { "focus_follows_mouse", cmd_focus_follows_mouse }, 483 { "focus_follows_mouse", cmd_focus_follows_mouse },
471 { "fullscreen", cmd_fullscreen }, 484 { "fullscreen", cmd_fullscreen },
diff --git a/sway/handlers.c b/sway/handlers.c
index d18be253..2a5113cc 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -14,8 +14,13 @@
14#include "container.h" 14#include "container.h"
15#include "focus.h" 15#include "focus.h"
16 16
17uint32_t keys_pressed[32];
18
17static struct wlc_origin mouse_origin; 19static struct wlc_origin mouse_origin;
18 20
21static bool m1_held = false;
22static bool m2_held = false;
23
19static bool pointer_test(swayc_t *view, void *_origin) { 24static bool pointer_test(swayc_t *view, void *_origin) {
20 const struct wlc_origin *origin = _origin; 25 const struct wlc_origin *origin = _origin;
21 //Determine the output that the view is under 26 //Determine the output that the view is under
@@ -144,10 +149,10 @@ static bool handle_view_created(wlc_handle handle) {
144 locked_container_focus = true; 149 locked_container_focus = true;
145 break; 150 break;
146 //set modals as floating containers 151 //set modals as floating containers
147 case WLC_BIT_POPUP:
148 case WLC_BIT_MODAL: 152 case WLC_BIT_MODAL:
149 wlc_view_bring_to_front(handle); 153 wlc_view_bring_to_front(handle);
150 newview = new_floating_view(handle); 154 newview = new_floating_view(handle);
155 case WLC_BIT_POPUP:
151 break; 156 break;
152 } 157 }
153 if (newview) { 158 if (newview) {
@@ -166,9 +171,9 @@ static void handle_view_destroyed(wlc_handle handle) {
166 //regular view created regularly 171 //regular view created regularly
167 case 0: 172 case 0:
168 case WLC_BIT_MODAL: 173 case WLC_BIT_MODAL:
169 case WLC_BIT_POPUP:
170 if (view) { 174 if (view) {
171 arrange_windows(destroy_view(view), -1, -1); 175 swayc_t *parent = destroy_view(view);
176 arrange_windows(parent, -1, -1);
172 if (!focused || focused == view) { 177 if (!focused || focused == view) {
173 set_focused_container(container_under_pointer()); 178 set_focused_container(container_under_pointer());
174 } 179 }
@@ -181,6 +186,7 @@ static void handle_view_destroyed(wlc_handle handle) {
181 //Takes container focus 186 //Takes container focus
182 case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED: 187 case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED:
183 locked_container_focus = false; 188 locked_container_focus = false;
189 case WLC_BIT_POPUP:
184 break; 190 break;
185 } 191 }
186 set_focused_container(get_focused_view(&root_container)); 192 set_focused_container(get_focused_view(&root_container));
@@ -250,7 +256,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
250 return false; 256 return false;
251 } 257 }
252 static uint8_t head = 0; 258 static uint8_t head = 0;
253 static uint32_t array[QSIZE];
254 bool cmd_success = false; 259 bool cmd_success = false;
255 260
256 struct sway_mode *mode = config->current_mode; 261 struct sway_mode *mode = config->current_mode;
@@ -259,13 +264,13 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
259 264
260 //Find key, if it has been pressed 265 //Find key, if it has been pressed
261 int mid = 0; 266 int mid = 0;
262 while (mid < head && array[mid] != sym) { 267 while (mid < head && keys_pressed[mid] != sym) {
263 ++mid; 268 ++mid;
264 } 269 }
265 if (state == WLC_KEY_STATE_PRESSED && mid == head && head + 1 < QSIZE) { 270 if (state == WLC_KEY_STATE_PRESSED && mid == head && head + 1 < QSIZE) {
266 array[head++] = sym; 271 keys_pressed[head++] = sym;
267 } else if (state == WLC_KEY_STATE_RELEASED && mid < head) { 272 } else if (state == WLC_KEY_STATE_RELEASED && mid < head) {
268 memmove(array + mid, array + mid + 1, sizeof*array * (--head - mid)); 273 memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--head - mid));
269 } 274 }
270 // TODO: reminder to check conflicts with mod+q+a versus mod+q 275 // TODO: reminder to check conflicts with mod+q+a versus mod+q
271 int i; 276 int i;
@@ -280,7 +285,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
280 xkb_keysym_t *key = binding->keys->items[j]; 285 xkb_keysym_t *key = binding->keys->items[j];
281 uint8_t k; 286 uint8_t k;
282 for (k = 0; k < head; ++k) { 287 for (k = 0; k < head; ++k) {
283 if (array[k] == *key) { 288 if (keys_pressed[k] == *key) {
284 match = true; 289 match = true;
285 break; 290 break;
286 } 291 }
@@ -291,12 +296,12 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
291 } 296 }
292 297
293 if (match) { 298 if (match) {
294 //Remove matched keys from array 299 //Remove matched keys from keys_pressed
295 int j; 300 int j;
296 for (j = 0; j < binding->keys->length; ++j) { 301 for (j = 0; j < binding->keys->length; ++j) {
297 uint8_t k; 302 uint8_t k;
298 for (k = 0; k < head; ++k) { 303 for (k = 0; k < head; ++k) {
299 memmove(array + k, array + k + 1, sizeof*array * (--head - k)); 304 memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--head - k));
300 break; 305 break;
301 } 306 }
302 } 307 }
@@ -311,13 +316,100 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
311 return cmd_success; 316 return cmd_success;
312} 317}
313 318
314static bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct wlc_origin *origin) { 319static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_origin *origin) {
315 static wlc_handle prev_view = 0; 320 static struct wlc_origin prev_pos;
321 static wlc_handle prev_handle = 0;
316 mouse_origin = *origin; 322 mouse_origin = *origin;
317 if (config->focus_follows_mouse && prev_view != view) { 323 bool changed_floating = false;
324 int i = 0;
325 // Do checks to determine if proper keys are being held
326 swayc_t *view = active_workspace->focused;
327 if (m1_held) {
328 if (view->is_floating) {
329 while (keys_pressed[i++]) {
330 if (keys_pressed[i] == config->floating_mod) {
331 int dx = mouse_origin.x - prev_pos.x;
332 int dy = mouse_origin.y - prev_pos.y;
333 sway_log(L_DEBUG, "Moving from px: %d to cx: %d and from py: %d to cy: %d", prev_pos.x, mouse_origin.x, prev_pos.y, mouse_origin.y);
334 sway_log(L_DEBUG, "Moving: dx: %d, dy: %d", dx, dy);
335
336 view->x += dx;
337 view->y += dy;
338 changed_floating = true;
339 break;
340 }
341 }
342 }
343 } else if (m2_held) {
344 if (view->is_floating) {
345 while (keys_pressed[i++]) {
346 if (keys_pressed[i] == config->floating_mod) {
347 int dx = mouse_origin.x - prev_pos.x;
348 int dy = mouse_origin.y - prev_pos.y;
349 sway_log(L_DEBUG, "Moving from px: %d to cx: %d and from py: %d to cy: %d", prev_pos.x, mouse_origin.x, prev_pos.y, mouse_origin.y);
350 sway_log(L_INFO, "Moving: dx: %d, dy: %d", dx, dy);
351
352 // Move and resize the view based on the dx/dy and mouse position
353 int midway_x = view->x + view->width/2;
354 int midway_y = view->y + view->height/2;
355
356 if (dx < 0) {
357 changed_floating = true;
358 if (mouse_origin.x > midway_x) {
359 sway_log(L_INFO, "Downsizing view to the left");
360 view->width += dx;
361 } else {
362 sway_log(L_INFO, "Upsizing view to the left");
363 view->x += dx;
364 view->width -= dx;
365 }
366 } else if (dx > 0){
367 changed_floating = true;
368 if (mouse_origin.x > midway_x) {
369 sway_log(L_INFO, "Upsizing to the right");
370 view->width += dx;
371 } else {
372 sway_log(L_INFO, "Downsizing to the right");
373 view->x += dx;
374 view->width -= dx;
375 }
376 }
377
378 if (dy < 0) {
379 changed_floating = true;
380 if (mouse_origin.y > midway_y) {
381 sway_log(L_INFO, "Downsizing view to the top");
382 view->height += dy;
383 } else {
384 sway_log(L_INFO, "Upsizing the view to the top");
385 view->y += dy;
386 view->height -= dy;
387 }
388 } else if (dy > 0) {
389 changed_floating = true;
390 if (mouse_origin.y > midway_y) {
391 sway_log(L_INFO, "Upsizing to the bottom");
392 view->height += dy;
393 } else {
394 sway_log(L_INFO, "Downsizing to the bottom");
395 view->y += dy;
396 view->height -= dy;
397 }
398 }
399 break;
400 }
401 }
402 }
403 }
404 if (config->focus_follows_mouse && prev_handle != handle) {
318 set_focused_container(container_under_pointer()); 405 set_focused_container(container_under_pointer());
319 } 406 }
320 prev_view = view; 407 prev_handle = handle;
408 prev_pos = mouse_origin;
409 if (changed_floating) {
410 arrange_windows(view, -1, -1);
411 return true;
412 }
321 return false; 413 return false;
322} 414}
323 415
@@ -325,9 +417,24 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
325 uint32_t button, enum wlc_button_state state) { 417 uint32_t button, enum wlc_button_state state) {
326 swayc_t *focused = get_focused_container(&root_container); 418 swayc_t *focused = get_focused_container(&root_container);
327 if (state == WLC_BUTTON_STATE_PRESSED) { 419 if (state == WLC_BUTTON_STATE_PRESSED) {
420 sway_log(L_DEBUG, "Mouse button %u pressed", button);
421 if (button == 272) {
422 m1_held = true;
423 }
424 if (button == 273) {
425 m2_held = true;
426 }
328 swayc_t *pointer = container_under_pointer(); 427 swayc_t *pointer = container_under_pointer();
329 set_focused_container(pointer); 428 set_focused_container(pointer);
330 return (pointer && pointer != focused); 429 return (pointer && pointer != focused);
430 } else {
431 sway_log(L_DEBUG, "Mouse button %u released", button);
432 if (button == 272) {
433 m1_held = false;
434 }
435 if (button == 273) {
436 m2_held = false;
437 }
331 } 438 }
332 return false; 439 return false;
333} 440}