diff --git a/action.c b/action.c index abc37e5..42d1da8 100644 --- a/action.c +++ b/action.c @@ -100,7 +100,7 @@ void action_find_or_start(void *data, int num, Client *cli) void action_move_monitor(void *data, int num, Client *cli) { if (!cli) return; - cli->monitor = MAX(0, MIN(current_mon+num, nmonitors-1)); + cli->monitor = monitor_choose_by_direction(current_mon, num); client_place_spot(cli, cli->spot, cli->monitor, 1); client_raise_family(cli); current_mon = cli->monitor; @@ -109,7 +109,7 @@ void action_move_monitor(void *data, int num, Client *cli) void action_focus_monitor(void *data, int num, Client *cli) { - int i, mon = MAX(0, MIN(current_mon+num, nmonitors-1)); + int i, mon = monitor_choose_by_direction(current_mon, num); if (!spot_focus_top_window(current_spot, mon, None)) for_spots(i) if (spot_focus_top_window(i, mon, None)) break; spot_warp_pointer(current_spot, current_mon); diff --git a/config.c b/config.c index a7079f2..6eb64bd 100644 --- a/config.c +++ b/config.c @@ -411,7 +411,7 @@ configure() if (strcmp(regex_matches[3], "spot3") == 0) num = SPOT3; } else - if (0 == strcmp(regex_matches[2], "action_move_direction") || 0 == strcmp(regex_matches[2], "action_focus_direction")) + if (0 == strcmp(regex_matches[2], "action_move_direction") || 0 == strcmp(regex_matches[2], "action_focus_direction") || 0 == strcmp(regex_matches[2], "action_move_monitor") || 0 == strcmp(regex_matches[2], "action_focus_monitor")) { if (strcmp(regex_matches[3], "left" ) == 0) num = LEFT; if (strcmp(regex_matches[3], "right") == 0) num = RIGHT; @@ -424,7 +424,7 @@ configure() data = regex_matches[3]; } else - if (0 == strcmp(regex_matches[2], "action_raise_nth") || 0 == strcmp(regex_matches[2], "action_move_monitor") || 0 == strcmp(regex_matches[2], "action_focus_monitor")) + if (0 == strcmp(regex_matches[2], "action_raise_nth")) { num = strtol(regex_matches[3], NULL, 10); } diff --git a/config.h b/config.h index 74dc266..97491c5 100644 --- a/config.h +++ b/config.h @@ -49,8 +49,9 @@ Layout layouts[] = { // Look at xrandr output to determine your monitor order. - { .spot_start = SMART, .spot1_align = LEFT, .spot1_width_pct = 60, .spot2_height_pct = 60 }, // primary monitor - { .spot_start = SMART, .spot1_align = RIGHT, .spot1_width_pct = 60, .spot2_height_pct = 60 }, // secondary monitor, etc... + { .spot_start = SMART, .spot1_align = LEFT, .spot1_width_pct = 60, .spot2_height_pct = 50 }, // primary monitor + { .spot_start = SMART, .spot1_align = LEFT, .spot1_width_pct = 60, .spot2_height_pct = 60 }, // secondary monitor, etc... + { .spot_start = SMART, .spot1_align = LEFT, .spot1_width_pct = 60, .spot2_height_pct = 60 }, // secondary monitor, etc... }; // Available actions... @@ -62,8 +63,8 @@ Layout layouts[] = { // action_cycle // action_command // action_find_or_start -// action_move_monitor -// action_focus_monitor +// action_move_monitor .num = UP/DOWN/LEFT/RIGHT +// action_focus_monitor .num = UP/DOWN/LEFT/RIGHT // action_fullscreen // action_maximize_vert // action_maximize_horz diff --git a/monitor.c b/monitor.c new file mode 100644 index 0000000..bb05d8e --- /dev/null +++ b/monitor.c @@ -0,0 +1,71 @@ +/* + +MIT/X11 License +Copyright (c) 2016 Sean Pringle + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +int monitor_choose_by_direction(int cmon, int dir) +{ + int mon = cmon; + int i; Monitor *m; + if (dir == LEFT) + { + for_monitors(i, m) + if (OVERLAP(m->y, m->h, monitors[cmon].y, monitors[cmon].h) && m->x < monitors[cmon].x && (mon == cmon || m->x >= monitors[mon].x)) + mon = i; + if (mon == cmon) for_monitors(i, m) + if (m->x < monitors[cmon].x && (mon == cmon || m->x >= monitors[mon].x)) + mon = i; + } + else + if (dir == RIGHT) + { + for_monitors(i, m) + if (OVERLAP(m->y, m->h, monitors[cmon].y, monitors[cmon].h) && m->x >= monitors[cmon].x + monitors[cmon].w && (mon == cmon || m->x <= monitors[mon].x)) + mon = i; + if (mon == cmon) for_monitors(i, m) + if (m->x >= monitors[cmon].x + monitors[cmon].w && (mon == cmon || m->x <= monitors[mon].x)) + mon = i; + } + else + if (dir == UP) + { + for_monitors(i, m) + if (OVERLAP(m->x, m->w, monitors[cmon].x, monitors[cmon].w) && m->y < monitors[cmon].y && (mon == cmon || m->y >= monitors[mon].y)) + mon = i; + if (mon == cmon) for_monitors(i, m) + if (m->y < monitors[cmon].y && (mon == cmon || m->y >= monitors[mon].y)) + mon = i; + } + else + if (dir == DOWN) + { + for_monitors(i, m) + if (OVERLAP(m->x, m->w, monitors[cmon].x, monitors[cmon].w) && m->y >= monitors[cmon].y + monitors[cmon].h && (mon == cmon || m->y <= monitors[mon].y)) + mon = i; + if (mon == cmon) for_monitors(i, m) + if (m->y >= monitors[cmon].y + monitors[cmon].h && (mon == cmon || m->y <= monitors[mon].y)) + mon = i; + } + return mon; +} diff --git a/xoat.c b/xoat.c index b6eb529..47247f4 100644 --- a/xoat.c +++ b/xoat.c @@ -216,6 +216,7 @@ void exec_cmd(char *cmd) exit(EXIT_FAILURE); } +#include "monitor.c" #include "window.c" #include "ewmh.c" #include "client.c" diff --git a/xoatrc b/xoatrc index f91808b..42f5438 100644 --- a/xoatrc +++ b/xoatrc @@ -110,12 +110,12 @@ bind Mod4+h action_maximize_horz bind Mod4+m action_maximize # Switch focus between monitors. -bind Mod4+Next action_focus_monitor -1 -bind Mod4+Prior action_focus_monitor +1 +bind Mod4+Next action_focus_monitor right +bind Mod4+Prior action_focus_monitor left # Move windows between monitors. -bind Mod4+Shift+Next action_move_monitor -1 -bind Mod4+Shift+Prior action_move_monitor +1 +bind Mod4+Shift+Next action_move_monitor right +bind Mod4+Shift+Prior action_move_monitor left # Launchers bind Mod4+x action_command dmenu_run @@ -138,4 +138,4 @@ bind F4 action_find_or_start sublime-text # Consider carefully if this is really what you want. Launch commands # will be run on startup and on every "xoat restart" there after... # launch xterm -# launch xsetroot -cursor_name left_ptr \ No newline at end of file +# launch xsetroot -cursor_name left_ptr