diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-12-14 17:14:49 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-12-14 17:14:49 -0500 |
commit | 42a85431eec1472e18cf886e02a629cda46f8123 (patch) | |
tree | 1bd0b17ccd7f8465ec6dcd07fef2753383da06c6 | |
parent | Merge pull request #319 from mikkeloscar/bar-mode (diff) | |
parent | Lookup dragging key when in dragging mode (diff) | |
download | sway-42a85431eec1472e18cf886e02a629cda46f8123.tar.gz sway-42a85431eec1472e18cf886e02a629cda46f8123.tar.zst sway-42a85431eec1472e18cf886e02a629cda46f8123.zip |
Merge pull request #320 from mikkeloscar/configure-mouse-btn2
Lookup dragging key when in dragging mode
-rw-r--r-- | include/config.h | 2 | ||||
-rw-r--r-- | sway/commands.c | 17 | ||||
-rw-r--r-- | sway/config.c | 2 | ||||
-rw-r--r-- | sway/input_state.c | 93 |
4 files changed, 93 insertions, 21 deletions
diff --git a/include/config.h b/include/config.h index 0f3ce550..a8370532 100644 --- a/include/config.h +++ b/include/config.h | |||
@@ -119,6 +119,8 @@ struct sway_config { | |||
119 | struct bar_config bar; | 119 | struct bar_config bar; |
120 | struct bar_config *current_bar; | 120 | struct bar_config *current_bar; |
121 | uint32_t floating_mod; | 121 | uint32_t floating_mod; |
122 | uint32_t dragging_key; | ||
123 | uint32_t resizing_key; | ||
122 | enum swayc_layouts default_orientation; | 124 | enum swayc_layouts default_orientation; |
123 | enum swayc_layouts default_layout; | 125 | enum swayc_layouts default_layout; |
124 | 126 | ||
diff --git a/sway/commands.c b/sway/commands.c index a394c69d..aa4cb89e 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -386,14 +386,14 @@ static struct cmd_results *cmd_floating(int argc, char **argv) { | |||
386 | 386 | ||
387 | static struct cmd_results *cmd_floating_mod(int argc, char **argv) { | 387 | static struct cmd_results *cmd_floating_mod(int argc, char **argv) { |
388 | struct cmd_results *error = NULL; | 388 | struct cmd_results *error = NULL; |
389 | if ((error = checkarg(argc, "floating_modifier", EXPECTED_EQUAL_TO, 1))) { | 389 | if ((error = checkarg(argc, "floating_modifier", EXPECTED_AT_LEAST, 1))) { |
390 | return error; | 390 | return error; |
391 | } | 391 | } |
392 | int i, j; | 392 | int i, j; |
393 | list_t *split = split_string(argv[0], "+"); | 393 | list_t *split = split_string(argv[0], "+"); |
394 | config->floating_mod = 0; | 394 | config->floating_mod = 0; |
395 | 395 | ||
396 | // set modifer keys | 396 | // set modifier keys |
397 | for (i = 0; i < split->length; ++i) { | 397 | for (i = 0; i < split->length; ++i) { |
398 | for (j = 0; j < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++j) { | 398 | for (j = 0; j < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++j) { |
399 | if (strcasecmp(modifiers[j].name, split->items[i]) == 0) { | 399 | if (strcasecmp(modifiers[j].name, split->items[i]) == 0) { |
@@ -406,6 +406,19 @@ static struct cmd_results *cmd_floating_mod(int argc, char **argv) { | |||
406 | error = cmd_results_new(CMD_INVALID, "floating_modifier", "Unknown keys %s", argv[0]); | 406 | error = cmd_results_new(CMD_INVALID, "floating_modifier", "Unknown keys %s", argv[0]); |
407 | return error; | 407 | return error; |
408 | } | 408 | } |
409 | |||
410 | if (argc >= 2) { | ||
411 | if (strcasecmp("inverse", argv[1]) == 0) { | ||
412 | config->dragging_key = M_RIGHT_CLICK; | ||
413 | config->resizing_key = M_LEFT_CLICK; | ||
414 | } else if (strcasecmp("normal", argv[1]) == 0) { | ||
415 | config->dragging_key = M_LEFT_CLICK; | ||
416 | config->resizing_key = M_RIGHT_CLICK; | ||
417 | } else { | ||
418 | error = cmd_results_new(CMD_INVALID, "floating_modifier", "Invalid definition %s", argv[1]); | ||
419 | return error; | ||
420 | } | ||
421 | } | ||
409 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 422 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
410 | } | 423 | } |
411 | 424 | ||
diff --git a/sway/config.c b/sway/config.c index bd3cf4e6..2a1f0310 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -115,6 +115,8 @@ static void config_defaults(struct sway_config *config) { | |||
115 | list_add(config->modes, config->current_mode); | 115 | list_add(config->modes, config->current_mode); |
116 | 116 | ||
117 | config->floating_mod = 0; | 117 | config->floating_mod = 0; |
118 | config->dragging_key = M_LEFT_CLICK; | ||
119 | config->resizing_key = M_RIGHT_CLICK; | ||
118 | config->default_layout = L_NONE; | 120 | config->default_layout = L_NONE; |
119 | config->default_orientation = L_NONE; | 121 | config->default_orientation = L_NONE; |
120 | // Flags | 122 | // Flags |
diff --git a/sway/input_state.c b/sway/input_state.c index 88506c92..25308a77 100644 --- a/sway/input_state.c +++ b/sway/input_state.c | |||
@@ -194,8 +194,16 @@ void center_pointer_on(swayc_t *view) { | |||
194 | 194 | ||
195 | // Mode set left/right click | 195 | // Mode set left/right click |
196 | 196 | ||
197 | static void pointer_mode_set_left(void) { | 197 | static void pointer_mode_set_dragging(void) { |
198 | set_initial_view(pointer_state.left.view); | 198 | switch (config->dragging_key) { |
199 | case M_LEFT_CLICK: | ||
200 | set_initial_view(pointer_state.left.view); | ||
201 | break; | ||
202 | case M_RIGHT_CLICK: | ||
203 | set_initial_view(pointer_state.right.view); | ||
204 | break; | ||
205 | } | ||
206 | |||
199 | if (initial.ptr->is_floating) { | 207 | if (initial.ptr->is_floating) { |
200 | pointer_state.mode = M_DRAGGING | M_FLOATING; | 208 | pointer_state.mode = M_DRAGGING | M_FLOATING; |
201 | } else { | 209 | } else { |
@@ -208,8 +216,15 @@ static void pointer_mode_set_left(void) { | |||
208 | } | 216 | } |
209 | } | 217 | } |
210 | 218 | ||
211 | static void pointer_mode_set_right(void) { | 219 | static void pointer_mode_set_resizing(void) { |
212 | set_initial_view(pointer_state.right.view); | 220 | switch (config->resizing_key) { |
221 | case M_LEFT_CLICK: | ||
222 | set_initial_view(pointer_state.left.view); | ||
223 | break; | ||
224 | case M_RIGHT_CLICK: | ||
225 | set_initial_view(pointer_state.right.view); | ||
226 | break; | ||
227 | } | ||
213 | // Setup locking information | 228 | // Setup locking information |
214 | int midway_x = initial.ptr->x + initial.ptr->width/2; | 229 | int midway_x = initial.ptr->x + initial.ptr->width/2; |
215 | int midway_y = initial.ptr->y + initial.ptr->height/2; | 230 | int midway_y = initial.ptr->y + initial.ptr->height/2; |
@@ -233,15 +248,19 @@ void pointer_mode_set(uint32_t button, bool condition) { | |||
233 | // switch on drag/resize mode | 248 | // switch on drag/resize mode |
234 | switch (pointer_state.mode & (M_DRAGGING | M_RESIZING)) { | 249 | switch (pointer_state.mode & (M_DRAGGING | M_RESIZING)) { |
235 | case M_DRAGGING: | 250 | case M_DRAGGING: |
236 | // end drag mode when left click is unpressed | 251 | // end drag mode when 'dragging' click is unpressed |
237 | if (!pointer_state.left.held) { | 252 | if (config->dragging_key == M_LEFT_CLICK && !pointer_state.left.held) { |
253 | pointer_state.mode = 0; | ||
254 | } else if (config->dragging_key == M_RIGHT_CLICK && !pointer_state.right.held) { | ||
238 | pointer_state.mode = 0; | 255 | pointer_state.mode = 0; |
239 | } | 256 | } |
240 | break; | 257 | break; |
241 | 258 | ||
242 | case M_RESIZING: | 259 | case M_RESIZING: |
243 | // end resize mode when right click is unpressed | 260 | // end resize mode when 'resizing' click is unpressed |
244 | if (!pointer_state.right.held) { | 261 | if (config->resizing_key == M_LEFT_CLICK && !pointer_state.left.held) { |
262 | pointer_state.mode = 0; | ||
263 | } else if (config->resizing_key == M_RIGHT_CLICK && !pointer_state.right.held) { | ||
245 | pointer_state.mode = 0; | 264 | pointer_state.mode = 0; |
246 | } | 265 | } |
247 | break; | 266 | break; |
@@ -255,19 +274,27 @@ void pointer_mode_set(uint32_t button, bool condition) { | |||
255 | 274 | ||
256 | // Set mode depending on current button press | 275 | // Set mode depending on current button press |
257 | switch (button) { | 276 | switch (button) { |
258 | // Start dragging mode | 277 | // Start left-click mode |
259 | case M_LEFT_CLICK: | 278 | case M_LEFT_CLICK: |
260 | // if button release dont do anything | 279 | // if button release dont do anything |
261 | if (pointer_state.left.held) { | 280 | if (pointer_state.left.held) { |
262 | pointer_mode_set_left(); | 281 | if (config->dragging_key == M_LEFT_CLICK) { |
282 | pointer_mode_set_dragging(); | ||
283 | } else if (config->resizing_key == M_LEFT_CLICK) { | ||
284 | pointer_mode_set_resizing(); | ||
285 | } | ||
263 | } | 286 | } |
264 | break; | 287 | break; |
265 | 288 | ||
266 | // Start resize mode | 289 | // Start right-click mode |
267 | case M_RIGHT_CLICK: | 290 | case M_RIGHT_CLICK: |
268 | // if button release dont do anyhting | 291 | // if button release dont do anyhting |
269 | if (pointer_state.right.held) { | 292 | if (pointer_state.right.held) { |
270 | pointer_mode_set_right(); | 293 | if (config->dragging_key == M_RIGHT_CLICK) { |
294 | pointer_mode_set_dragging(); | ||
295 | } else if (config->resizing_key == M_RIGHT_CLICK) { | ||
296 | pointer_mode_set_resizing(); | ||
297 | } | ||
271 | } | 298 | } |
272 | break; | 299 | break; |
273 | } | 300 | } |
@@ -287,8 +314,17 @@ void pointer_mode_update(void) { | |||
287 | switch (pointer_state.mode) { | 314 | switch (pointer_state.mode) { |
288 | case M_FLOATING | M_DRAGGING: | 315 | case M_FLOATING | M_DRAGGING: |
289 | // Update position | 316 | // Update position |
290 | dx -= pointer_state.left.x; | 317 | switch (config->dragging_key) { |
291 | dy -= pointer_state.left.y; | 318 | case M_LEFT_CLICK: |
319 | dx -= pointer_state.left.x; | ||
320 | dy -= pointer_state.left.y; | ||
321 | break; | ||
322 | case M_RIGHT_CLICK: | ||
323 | dx -= pointer_state.right.x; | ||
324 | dy -= pointer_state.right.y; | ||
325 | break; | ||
326 | } | ||
327 | |||
292 | if (initial.x + dx != initial.ptr->x) { | 328 | if (initial.x + dx != initial.ptr->x) { |
293 | initial.ptr->x = initial.x + dx; | 329 | initial.ptr->x = initial.x + dx; |
294 | } | 330 | } |
@@ -299,9 +335,19 @@ void pointer_mode_update(void) { | |||
299 | break; | 335 | break; |
300 | 336 | ||
301 | case M_FLOATING | M_RESIZING: | 337 | case M_FLOATING | M_RESIZING: |
302 | dx -= pointer_state.right.x; | 338 | switch (config->resizing_key) { |
303 | dy -= pointer_state.right.y; | 339 | case M_LEFT_CLICK: |
304 | initial.ptr = pointer_state.right.view; | 340 | dx -= pointer_state.left.x; |
341 | dy -= pointer_state.left.y; | ||
342 | initial.ptr = pointer_state.left.view; | ||
343 | break; | ||
344 | case M_RIGHT_CLICK: | ||
345 | dx -= pointer_state.right.x; | ||
346 | dy -= pointer_state.right.y; | ||
347 | initial.ptr = pointer_state.right.view; | ||
348 | break; | ||
349 | } | ||
350 | |||
305 | if (lock.left) { | 351 | if (lock.left) { |
306 | if (initial.w + dx > min_sane_w) { | 352 | if (initial.w + dx > min_sane_w) { |
307 | initial.ptr->width = initial.w + dx; | 353 | initial.ptr->width = initial.w + dx; |
@@ -341,8 +387,17 @@ void pointer_mode_update(void) { | |||
341 | break; | 387 | break; |
342 | 388 | ||
343 | case M_TILING | M_RESIZING: | 389 | case M_TILING | M_RESIZING: |
344 | dx -= pointer_state.right.x; | 390 | switch (config->resizing_key) { |
345 | dy -= pointer_state.right.y; | 391 | case M_LEFT_CLICK: |
392 | dx -= pointer_state.left.x; | ||
393 | dy -= pointer_state.left.y; | ||
394 | break; | ||
395 | case M_RIGHT_CLICK: | ||
396 | dx -= pointer_state.right.x; | ||
397 | dy -= pointer_state.right.y; | ||
398 | break; | ||
399 | } | ||
400 | |||
346 | // resize if we can | 401 | // resize if we can |
347 | if (initial.horiz.ptr) { | 402 | if (initial.horiz.ptr) { |
348 | if (lock.left) { | 403 | if (lock.left) { |