support more complex monitor layouts with move/focus actions using left|right|up|down

Conflicts:
	config.h
This commit is contained in:
Sean Pringle
2016-06-30 09:45:21 +10:00
parent 0e0fa13f32
commit d7de4ff112
6 changed files with 86 additions and 13 deletions

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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

71
monitor.c Normal file
View File

@@ -0,0 +1,71 @@
/*
MIT/X11 License
Copyright (c) 2016 Sean Pringle <sean.pringle@gmail.com>
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;
}

1
xoat.c
View File

@@ -216,6 +216,7 @@ void exec_cmd(char *cmd)
exit(EXIT_FAILURE);
}
#include "monitor.c"
#include "window.c"
#include "ewmh.c"
#include "client.c"

10
xoatrc
View File

@@ -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
# launch xsetroot -cursor_name left_ptr