Compare commits

...

10 Commits

Author SHA1 Message Date
27f4b1dd38 Forked. Fix for menu popup bugs. 2026-02-20 18:33:01 +01:00
Sean Pringle
d7de4ff112 support more complex monitor layouts with move/focus actions using left|right|up|down
Conflicts:
	config.h
2016-06-30 09:50:17 +10:00
Sean Pringle
0e0fa13f32 initialize current_spot and current_mon 2016-02-11 20:18:20 +11:00
Sean Pringle
d36e287884 toggle NET_WM_STATE_ABOVE with mod4+a 2015-12-11 21:06:02 +10:00
Sean Pringle
4a072964ec support NET_WM_STATE_ABOVE in spot 3 2015-12-11 21:05:02 +10:00
Sean Pringle
d26a0a50f3 partial utf8 support (works in titles; not in menu input) 2015-12-11 21:04:49 +10:00
Sean Pringle
7ae527002b don't warp pointer on client message 2015-03-28 17:10:08 +10:00
Sean Pringle
3338221805 xoatrc regex bug action_move_monitor action_focus_monitor 2015-03-28 16:25:04 +10:00
Sean Pringle
de1043ece3 action_find_or_start match WM_CLASS substring 2015-02-08 18:31:45 +10:00
Sean Pringle
62136f2977 mouse click segfault if titles disabled in .xoatrc yet enabled in config.h 2015-01-16 14:47:34 +10:00
14 changed files with 149 additions and 41 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
.env
xoat
xoat-debug

View File

@@ -1,6 +1,8 @@
xoat
====
Fork of [seanpringle](https://github.com/seanpringle)/[xoat](https://github.com/seanpringle/xoat)
*X Obstinate Asymmetric Tiler*
* Designed for wide screens, including multi-head support.

View File

@@ -27,8 +27,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
void action_move(void *data, int num, Client *cli)
{
if (!cli) return;
client_raise_family(cli);
client_place_spot(cli, num, cli->monitor, 1);
client_raise_family(cli);
current_spot = cli->spot; current_mon = cli->monitor;
spot_warp_pointer(cli->spot, cli->monitor);
}
@@ -36,8 +36,8 @@ void action_move(void *data, int num, Client *cli)
void action_move_direction(void *data, int num, Client *cli)
{
if (!cli) return;
client_raise_family(cli);
client_place_spot(cli, spot_choose_by_direction(cli->spot, cli->monitor, num), cli->monitor, 1);
client_raise_family(cli);
current_spot = cli->spot; current_mon = cli->monitor;
spot_warp_pointer(cli->spot, cli->monitor);
}
@@ -92,7 +92,7 @@ void action_find_or_start(void *data, int num, Client *cli)
{
int i; Client *c; char *class = data;
for_windows(i, c)
if (c->visible && c->manage && c->class && !strcasecmp(c->class, class))
if (c->visible && c->manage && c->class && strcasestr(c->class, class))
{ client_activate(c); spot_warp_pointer(c->spot, c->monitor); return; }
exec_cmd(class);
}
@@ -100,16 +100,16 @@ void action_find_or_start(void *data, int num, Client *cli)
void action_move_monitor(void *data, int num, Client *cli)
{
if (!cli) return;
client_raise_family(cli);
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;
spot_warp_pointer(cli->spot, cli->monitor);
}
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);
@@ -152,7 +152,14 @@ void action_maximize_horz(void *data, int num, Client *cli)
client_place_spot(cli, cli->spot, cli->monitor, 1);
}
void action_above(void *data, int num, Client *cli)
{
if (!cli) return;
cli->above = client_toggle_state(cli, atoms[_NET_WM_STATE_ABOVE]);
client_place_spot(cli, cli->spot, cli->monitor, 1);
}
void action_menu(void *data, int num, Client *cli)
{
menu_create(current_spot, current_mon);
}
}

1
atom.c
View File

@@ -53,6 +53,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
X(_NET_WM_STATE_MAXIMIZE_VERT),\
X(_NET_WM_STATE_MAXIMIZE_HORZ),\
X(_NET_WM_STATE_DEMANDS_ATTENTION),\
X(_NET_WM_STATE_ABOVE),\
X(WM_NAME),\
X(WM_DELETE_WINDOW),\
X(WM_CLIENT_LEADER),\

View File

@@ -112,6 +112,7 @@ Client* window_build_client(Window win)
c->full = client_has_state(c, atoms[_NET_WM_STATE_FULLSCREEN]);
c->maxv = client_has_state(c, atoms[_NET_WM_STATE_MAXIMIZE_VERT]);
c->maxh = client_has_state(c, atoms[_NET_WM_STATE_MAXIMIZE_HORZ]);
c->above = client_has_state(c, atoms[_NET_WM_STATE_ABOVE]);
GETPROP_LONG(win, atoms[XOAT_MAXIMIZE], &c->max, 1);
@@ -297,8 +298,13 @@ void client_raise_family(Client *c)
if (!c) return;
int i; Client *o; STACK_INIT(raise); STACK_INIT(family);
for_windows(i, o) if (o->type == atoms[_NET_WM_WINDOW_TYPE_DOCK])
client_stack_family(o, &raise);
for_windows(i, o)
{
if (o->type == atoms[_NET_WM_WINDOW_TYPE_DOCK])
client_stack_family(o, &raise);
if (o->above && c->spot != SPOT3 && o->spot == SPOT3)
client_stack_family(o, &raise);
}
while (c->transient && (o = window_build_client(c->transient)) && o->manage)
c = family.clients[family.depth++] = o;

View File

@@ -37,9 +37,12 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define CONFIG_MENU "menu"
#define CONFIG_UINT_NAMES CONFIG_BORDER "|" CONFIG_GAP "|" CONFIG_TITLE_ELLIPSIS
#define CONFIG_STR_NAMES CONFIG_BORDER_BLUR "|" CONFIG_BORDER_FOCUS "|" CONFIG_BORDER_URGENT "|" CONFIG_TITLE "|" CONFIG_TITLE_BLUR "|" CONFIG_TITLE_FOCUS "|" CONFIG_MENU
#define CONFIG_STR_NAMES CONFIG_BORDER_BLUR "|" CONFIG_BORDER_FOCUS "|" CONFIG_BORDER_URGENT "|" CONFIG_TITLE "|" \
CONFIG_TITLE_BLUR "|" CONFIG_TITLE_FOCUS "|" CONFIG_MENU
#define CONFIG_ACTIONS "action_move_direction|action_focus_direction|action_move|action_focus|action_close|action_cycle|action_raise_nth|action_command|action_find_or_start|action_move_monitor|action_focus_monitor|action_fullscreen|action_maximize_vert|action_maximize_horz|action_maximize|action_menu"
#define CONFIG_ACTIONS "action_move_direction|action_move_monitor|action_focus_monitor|action_focus_direction" \
"|action_move|action_focus|action_close|action_cycle|action_raise_nth|action_command|action_find_or_start" \
"|action_fullscreen|action_maximize_vert|action_maximize_horz|action_maximize|action_above|action_menu"
void
rtrim(char *str)
@@ -370,6 +373,7 @@ configure()
"action_maximize_vert",
"action_maximize_horz",
"action_maximize",
"action_above",
"action_menu",
};
void *actions[] = {
@@ -388,6 +392,7 @@ configure()
action_maximize_vert,
action_maximize_horz,
action_maximize,
action_above,
action_menu,
};
for (i = 0; i < sizeof(names) / sizeof(char*); i++)
@@ -406,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;
@@ -419,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);
}
@@ -448,7 +453,7 @@ configure()
if (regex_match("^launch[[:space:]]+(.+)$", tmp))
{
rtrim(regex_matches[1]);
settings.launchcmd_count++;
settings.launchcmds = realloc(settings.launchcmds, sizeof(char*) * settings.launchcmd_count);
settings.launchcmds[settings.launchcmd_count-1] = strdup(regex_matches[1]);

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,12 +63,13 @@ 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
// action_maximize
// action_above
// action_menu
// If using "AnyModifier" place those keys at the end of the array.
@@ -102,10 +104,11 @@ Binding keys[] = {
{ .mod = Mod4Mask, .key = XK_v, .act = action_maximize_vert },
{ .mod = Mod4Mask, .key = XK_h, .act = action_maximize_horz },
{ .mod = Mod4Mask, .key = XK_m, .act = action_maximize },
{ .mod = Mod4Mask, .key = XK_a, .act = action_above },
// Launcher
{ .mod = Mod4Mask, .key = XK_x, .act = action_command, .data = "dmenu_run" },
// Example
// { .mod = AnyModifier, .key = XK_F1, .act = action_find_or_start, .data = "xterm" },
};
};

24
event.c
View File

@@ -102,7 +102,8 @@ void map_notify(XEvent *e)
{
client_raise_family(c);
client_update_border(c);
client_set_focus(c);
if (!c->menu) // Only set focus if it's not a menu/popup
client_set_focus(c);
client_free(a);
ewmh_client_list();
update_bars();
@@ -113,12 +114,14 @@ void map_notify(XEvent *e)
void unmap_notify(XEvent *e)
{
// if this window was focused, find something else
if (e->xunmap.window == current && !spot_focus_top_window(current_spot, current_mon, current))
Client *c = window_build_client(e->xunmap.window);
// if this window was focused, and it's not a menu/popup, find something else
if (c && !c->menu && e->xunmap.window == current && !spot_focus_top_window(current_spot, current_mon, current))
{
int i; for_spots(i)
if (spot_focus_top_window(i, current_mon, current)) break;
}
client_free(c);
ewmh_client_list();
update_bars();
menu_update();
@@ -126,7 +129,8 @@ void unmap_notify(XEvent *e)
void key_press(XEvent *ev)
{
XKeyEvent *e = &ev->xkey; latest = e->time;
XKeyEvent *e = &ev->xkey;
latest_action = e->time;
KeySym key = XkbKeycodeToKeysym(display, e->keycode, 0, 0);
unsigned int state = e->state & ~(LockMask|NumlockMask);
while (XCheckTypedEvent(display, KeyPress, ev));
@@ -141,7 +145,7 @@ void key_press(XEvent *ev)
if (rc == -1)
menu_select();
return;
}
@@ -163,17 +167,18 @@ void key_press(XEvent *ev)
void button_press(XEvent *ev)
{
int i, j; Monitor *m;
XButtonEvent *e = &ev->xbutton; latest = e->time;
XButtonEvent *e = &ev->xbutton;
latest_action = e->time;
Client *c = window_build_client(e->subwindow);
if (c && c->manage)
client_activate(c);
else
if (TITLE)
if (settings.title)
for_monitors(i, m) for_spots(j)
if (m->bars[j]->window == e->subwindow)
if (m->bars[i] && m->bars[j]->window == e->subwindow)
spot_focus_top_window(j, i, None);
client_free(c);
XAllowEvents(display, ReplayPointer, CurrentTime);
XAllowEvents(display, ReplayPointer, latest_action);
}
void client_message(XEvent *ev)
@@ -195,7 +200,6 @@ void client_message(XEvent *ev)
if (e->message_type == atoms[_NET_ACTIVE_WINDOW])
{
client_activate(c);
spot_warp_pointer(c->spot, c->monitor);
}
else
if (e->message_type == atoms[_NET_CLOSE_WINDOW])

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

View File

@@ -103,6 +103,10 @@ void setup()
}
memmove(monitors, padded, sizeof(Monitor) * MONITORS);
// if spot_start is CURRENT, first window needs somewhere to go
current_spot = SPOT1;
current_mon = 0;
// calculate spot boxes
for_monitors(i, m)
{

View File

@@ -97,7 +97,7 @@ void textbox_extents(Textbox *tb)
int length = strlen(tb->text) + strlen(tb->prompt);
char *line = calloc(length + 1, sizeof(char));
sprintf(line, "%s%s", tb->prompt, tb->text);
XftTextExtents8(display, tb->font, (unsigned char*)line, length, &tb->extents);
XftTextExtentsUtf8(display, tb->font, (unsigned char*)line, length, &tb->extents);
free(line);
}
@@ -198,7 +198,7 @@ void textbox_draw(Textbox *tb)
if (length > 0 && isspace(line[length-1])) line[length-1] = '.';
// calc cursor position
XftTextExtents8(display, tb->font, (unsigned char*)line, cursor_offset, &extents);
XftTextExtentsUtf8(display, tb->font, (unsigned char*)line, cursor_offset, &extents);
cursor_x = extents.width;
// restore correct text string
@@ -206,7 +206,7 @@ void textbox_draw(Textbox *tb)
}
// calc full input text width
XftTextExtents8(display, tb->font, (unsigned char*)line, length, &extents);
XftTextExtentsUtf8(display, tb->font, (unsigned char*)line, length, &extents);
int line_width = extents.width;
int x = 0, y = tb->font->ascent;
@@ -214,7 +214,7 @@ void textbox_draw(Textbox *tb)
if (tb->flags & TB_CENTER) x = MAX(0, (tb->w - line_width) / 2);
// draw the text, including any prompt in edit mode
XftDrawString8(draw, &tb->color_fg, tb->font, x, y, (unsigned char*)line, length);
XftDrawStringUtf8(draw, &tb->color_fg, tb->font, x, y, (unsigned char*)line, length);
// draw the cursor
if (tb->flags & TB_EDITABLE)

View File

@@ -92,7 +92,7 @@ int window_send_clientmessage(Window target, Window subject, Atom atom, unsigned
e.xclient.message_type = atom;
e.xclient.window = subject;
e.xclient.data.l[0] = protocol;
e.xclient.data.l[1] = latest;
e.xclient.data.l[1] = latest_action;
e.xclient.send_event = True;
e.xclient.format = 32;
int r = XSendEvent(display, target, False, mask, &e) ?1:0;

6
xoat.c
View File

@@ -89,7 +89,7 @@ typedef struct _Client {
XWindowAttributes attr;
Window transient, leader;
Atom type, states[ATOMLIST+1];
short monitor, visible, manage, input, urgent, full, ours, maxv, maxh, bar, menu;
short monitor, visible, manage, input, urgent, full, ours, maxv, maxh, bar, menu, above;
unsigned long spot, max;
char *class;
} Client;
@@ -153,6 +153,7 @@ void action_fullscreen(void*, int, Client*);
void action_maximize_vert(void*, int, Client*);
void action_maximize_horz(void*, int, Client*);
void action_maximize(void*, int, Client*);
void action_above(void*, int, Client*);
void action_menu(void*, int, Client*);
#include "config.h"
@@ -189,7 +190,7 @@ void action_menu(void*, int, Client*);
#define for_monitors(i, m)\
for ((i) = 0; (i) < nmonitors && (m = &monitors[(i)]); (i)++)
Time latest;
Time latest_action;
char *self;
unsigned int NumlockMask;
Monitor monitors[MONITORS];
@@ -215,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