aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2015-12-14 17:14:49 -0500
committerDrew DeVault <sir@cmpwn.com>2015-12-14 17:14:49 -0500
commit42a85431eec1472e18cf886e02a629cda46f8123 (patch)
tree1bd0b17ccd7f8465ec6dcd07fef2753383da06c6
parentfa0f57cd045ef13aff02a9c25bf0c46226f1b55b (diff)
parent82af08d8e9c6b3d1770f022ed0e38e79bba582ea (diff)
Merge pull request #320 from mikkeloscar/configure-mouse-btn2
Lookup dragging key when in dragging mode
-rw-r--r--include/config.h2
-rw-r--r--sway/commands.c17
-rw-r--r--sway/config.c2
-rw-r--r--sway/input_state.c93
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 {
struct bar_config bar;
struct bar_config *current_bar;
uint32_t floating_mod;
+ uint32_t dragging_key;
+ uint32_t resizing_key;
enum swayc_layouts default_orientation;
enum swayc_layouts default_layout;
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) {
static struct cmd_results *cmd_floating_mod(int argc, char **argv) {
struct cmd_results *error = NULL;
- if ((error = checkarg(argc, "floating_modifier", EXPECTED_EQUAL_TO, 1))) {
+ if ((error = checkarg(argc, "floating_modifier", EXPECTED_AT_LEAST, 1))) {
return error;
}
int i, j;
list_t *split = split_string(argv[0], "+");
config->floating_mod = 0;
- // set modifer keys
+ // set modifier keys
for (i = 0; i < split->length; ++i) {
for (j = 0; j < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++j) {
if (strcasecmp(modifiers[j].name, split->items[i]) == 0) {
@@ -406,6 +406,19 @@ static struct cmd_results *cmd_floating_mod(int argc, char **argv) {
error = cmd_results_new(CMD_INVALID, "floating_modifier", "Unknown keys %s", argv[0]);
return error;
}
+
+ if (argc >= 2) {
+ if (strcasecmp("inverse", argv[1]) == 0) {
+ config->dragging_key = M_RIGHT_CLICK;
+ config->resizing_key = M_LEFT_CLICK;
+ } else if (strcasecmp("normal", argv[1]) == 0) {
+ config->dragging_key = M_LEFT_CLICK;
+ config->resizing_key = M_RIGHT_CLICK;
+ } else {
+ error = cmd_results_new(CMD_INVALID, "floating_modifier", "Invalid definition %s", argv[1]);
+ return error;
+ }
+ }
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
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) {
list_add(config->modes, config->current_mode);
config->floating_mod = 0;
+ config->dragging_key = M_LEFT_CLICK;
+ config->resizing_key = M_RIGHT_CLICK;
config->default_layout = L_NONE;
config->default_orientation = L_NONE;
// 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) {
// Mode set left/right click
-static void pointer_mode_set_left(void) {
- set_initial_view(pointer_state.left.view);
+static void pointer_mode_set_dragging(void) {
+ switch (config->dragging_key) {
+ case M_LEFT_CLICK:
+ set_initial_view(pointer_state.left.view);
+ break;
+ case M_RIGHT_CLICK:
+ set_initial_view(pointer_state.right.view);
+ break;
+ }
+
if (initial.ptr->is_floating) {
pointer_state.mode = M_DRAGGING | M_FLOATING;
} else {
@@ -208,8 +216,15 @@ static void pointer_mode_set_left(void) {
}
}
-static void pointer_mode_set_right(void) {
- set_initial_view(pointer_state.right.view);
+static void pointer_mode_set_resizing(void) {
+ switch (config->resizing_key) {
+ case M_LEFT_CLICK:
+ set_initial_view(pointer_state.left.view);
+ break;
+ case M_RIGHT_CLICK:
+ set_initial_view(pointer_state.right.view);
+ break;
+ }
// Setup locking information
int midway_x = initial.ptr->x + initial.ptr->width/2;
int midway_y = initial.ptr->y + initial.ptr->height/2;
@@ -233,15 +248,19 @@ void pointer_mode_set(uint32_t button, bool condition) {
// switch on drag/resize mode
switch (pointer_state.mode & (M_DRAGGING | M_RESIZING)) {
case M_DRAGGING:
- // end drag mode when left click is unpressed
- if (!pointer_state.left.held) {
+ // end drag mode when 'dragging' click is unpressed
+ if (config->dragging_key == M_LEFT_CLICK && !pointer_state.left.held) {
+ pointer_state.mode = 0;
+ } else if (config->dragging_key == M_RIGHT_CLICK && !pointer_state.right.held) {
pointer_state.mode = 0;
}
break;
case M_RESIZING:
- // end resize mode when right click is unpressed
- if (!pointer_state.right.held) {
+ // end resize mode when 'resizing' click is unpressed
+ if (config->resizing_key == M_LEFT_CLICK && !pointer_state.left.held) {
+ pointer_state.mode = 0;
+ } else if (config->resizing_key == M_RIGHT_CLICK && !pointer_state.right.held) {
pointer_state.mode = 0;
}
break;
@@ -255,19 +274,27 @@ void pointer_mode_set(uint32_t button, bool condition) {
// Set mode depending on current button press
switch (button) {
- // Start dragging mode
+ // Start left-click mode
case M_LEFT_CLICK:
// if button release dont do anything
if (pointer_state.left.held) {
- pointer_mode_set_left();
+ if (config->dragging_key == M_LEFT_CLICK) {
+ pointer_mode_set_dragging();
+ } else if (config->resizing_key == M_LEFT_CLICK) {
+ pointer_mode_set_resizing();
+ }
}
break;
- // Start resize mode
+ // Start right-click mode
case M_RIGHT_CLICK:
// if button release dont do anyhting
if (pointer_state.right.held) {
- pointer_mode_set_right();
+ if (config->dragging_key == M_RIGHT_CLICK) {
+ pointer_mode_set_dragging();
+ } else if (config->resizing_key == M_RIGHT_CLICK) {
+ pointer_mode_set_resizing();
+ }
}
break;
}
@@ -287,8 +314,17 @@ void pointer_mode_update(void) {
switch (pointer_state.mode) {
case M_FLOATING | M_DRAGGING:
// Update position
- dx -= pointer_state.left.x;
- dy -= pointer_state.left.y;
+ switch (config->dragging_key) {
+ case M_LEFT_CLICK:
+ dx -= pointer_state.left.x;
+ dy -= pointer_state.left.y;
+ break;
+ case M_RIGHT_CLICK:
+ dx -= pointer_state.right.x;
+ dy -= pointer_state.right.y;
+ break;
+ }
+
if (initial.x + dx != initial.ptr->x) {
initial.ptr->x = initial.x + dx;
}
@@ -299,9 +335,19 @@ void pointer_mode_update(void) {
break;
case M_FLOATING | M_RESIZING:
- dx -= pointer_state.right.x;
- dy -= pointer_state.right.y;
- initial.ptr = pointer_state.right.view;
+ switch (config->resizing_key) {
+ case M_LEFT_CLICK:
+ dx -= pointer_state.left.x;
+ dy -= pointer_state.left.y;
+ initial.ptr = pointer_state.left.view;
+ break;
+ case M_RIGHT_CLICK:
+ dx -= pointer_state.right.x;
+ dy -= pointer_state.right.y;
+ initial.ptr = pointer_state.right.view;
+ break;
+ }
+
if (lock.left) {
if (initial.w + dx > min_sane_w) {
initial.ptr->width = initial.w + dx;
@@ -341,8 +387,17 @@ void pointer_mode_update(void) {
break;
case M_TILING | M_RESIZING:
- dx -= pointer_state.right.x;
- dy -= pointer_state.right.y;
+ switch (config->resizing_key) {
+ case M_LEFT_CLICK:
+ dx -= pointer_state.left.x;
+ dy -= pointer_state.left.y;
+ break;
+ case M_RIGHT_CLICK:
+ dx -= pointer_state.right.x;
+ dy -= pointer_state.right.y;
+ break;
+ }
+
// resize if we can
if (initial.horiz.ptr) {
if (lock.left) {