Merge pull request #4018 from orestisfl/reorder-docks
Sort dock clients by class and instance
This commit is contained in:
commit
0bce0d86bf
|
@ -685,19 +685,6 @@ static void handle_visibility_notify(xcb_visibility_notify_event_t *event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int strcasecmp_nullable(const char *a, const char *b) {
|
|
||||||
if (a == b) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (a == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (b == NULL) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return strcasecmp(a, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Comparison function to sort trayclients in ascending alphanumeric order
|
* Comparison function to sort trayclients in ascending alphanumeric order
|
||||||
* according to their class.
|
* according to their class.
|
||||||
|
@ -1816,6 +1803,8 @@ void reconfig_windows(bool redraw_bars) {
|
||||||
bar_height);
|
bar_height);
|
||||||
|
|
||||||
/* Set the WM_CLASS and WM_NAME (we don't need UTF-8) atoms */
|
/* Set the WM_CLASS and WM_NAME (we don't need UTF-8) atoms */
|
||||||
|
char *class;
|
||||||
|
int len = sasprintf(&class, "%s%ci3bar%c", config.bar_id, 0, 0);
|
||||||
xcb_void_cookie_t class_cookie;
|
xcb_void_cookie_t class_cookie;
|
||||||
class_cookie = xcb_change_property(xcb_connection,
|
class_cookie = xcb_change_property(xcb_connection,
|
||||||
XCB_PROP_MODE_REPLACE,
|
XCB_PROP_MODE_REPLACE,
|
||||||
|
@ -1823,8 +1812,8 @@ void reconfig_windows(bool redraw_bars) {
|
||||||
XCB_ATOM_WM_CLASS,
|
XCB_ATOM_WM_CLASS,
|
||||||
XCB_ATOM_STRING,
|
XCB_ATOM_STRING,
|
||||||
8,
|
8,
|
||||||
(strlen("i3bar") + 1) * 2,
|
len,
|
||||||
"i3bar\0i3bar\0");
|
class);
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
sasprintf(&name, "i3bar for output %s", walk->name);
|
sasprintf(&name, "i3bar for output %s", walk->name);
|
||||||
|
|
|
@ -181,6 +181,12 @@ ssize_t writeall_nonblock(int fd, const void *buf, size_t count);
|
||||||
*/
|
*/
|
||||||
ssize_t swrite(int fd, const void *buf, size_t count);
|
ssize_t swrite(int fd, const void *buf, size_t count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like strcasecmp but considers the case where either string is NULL.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int strcasecmp_nullable(const char *a, const char *b);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build an i3String from an UTF-8 encoded string.
|
* Build an i3String from an UTF-8 encoded string.
|
||||||
* Returns the newly-allocated i3String.
|
* Returns the newly-allocated i3String.
|
||||||
|
|
|
@ -110,3 +110,20 @@ ssize_t swrite(int fd, const void *buf, size_t count) {
|
||||||
else
|
else
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Like strcasecmp but considers the case where either string is NULL.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int strcasecmp_nullable(const char *a, const char *b) {
|
||||||
|
if (a == b) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (a == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (b == NULL) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return strcasecmp(a, b);
|
||||||
|
}
|
||||||
|
|
24
src/con.c
24
src/con.c
|
@ -132,6 +132,30 @@ static void _con_attach(Con *con, Con *parent, Con *previous, bool ignore_focus)
|
||||||
goto add_to_focus_head;
|
goto add_to_focus_head;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parent->type == CT_DOCKAREA) {
|
||||||
|
/* Insert dock client, sorting alphanumerically by class and then
|
||||||
|
* instance name. This makes dock client order deterministic. As a side
|
||||||
|
* effect, bars without a custom bar id will be sorted according to
|
||||||
|
* their declaration order in the config file. See #3491. */
|
||||||
|
current = NULL;
|
||||||
|
TAILQ_FOREACH (loop, nodes_head, nodes) {
|
||||||
|
int result = strcasecmp_nullable(con->window->class_class, loop->window->class_class);
|
||||||
|
if (result == 0) {
|
||||||
|
result = strcasecmp_nullable(con->window->class_instance, loop->window->class_instance);
|
||||||
|
}
|
||||||
|
if (result < 0) {
|
||||||
|
current = loop;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (current) {
|
||||||
|
TAILQ_INSERT_BEFORE(loop, con, nodes);
|
||||||
|
} else {
|
||||||
|
TAILQ_INSERT_TAIL(nodes_head, con, nodes);
|
||||||
|
}
|
||||||
|
goto add_to_focus_head;
|
||||||
|
}
|
||||||
|
|
||||||
if (con->type == CT_FLOATING_CON) {
|
if (con->type == CT_FLOATING_CON) {
|
||||||
DLOG("Inserting into floating containers\n");
|
DLOG("Inserting into floating containers\n");
|
||||||
TAILQ_INSERT_TAIL(&(parent->floating_head), con, floating_windows);
|
TAILQ_INSERT_TAIL(&(parent->floating_head), con, floating_windows);
|
||||||
|
|
|
@ -1148,9 +1148,7 @@ static bool handle_strut_partial_change(Con *con, xcb_get_property_reply_t *prop
|
||||||
|
|
||||||
/* attach the dock to the dock area */
|
/* attach the dock to the dock area */
|
||||||
con_detach(con);
|
con_detach(con);
|
||||||
con->parent = dockarea;
|
con_attach(con, dockarea, true);
|
||||||
TAILQ_INSERT_HEAD(&(dockarea->focus_head), con, focused);
|
|
||||||
TAILQ_INSERT_HEAD(&(dockarea->nodes_head), con, nodes);
|
|
||||||
|
|
||||||
tree_render();
|
tree_render();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue