Merge pull request #4018 from orestisfl/reorder-docks
Sort dock clients by class and instance
Ingo Bürk authored 4 years ago
GitHub committed 4 years ago
682 | 682 |
} else {
|
683 | 683 |
cont_child();
|
684 | 684 |
}
|
685 | |
}
|
686 | |
|
687 | |
static int strcasecmp_nullable(const char *a, const char *b) {
|
688 | |
if (a == b) {
|
689 | |
return 0;
|
690 | |
}
|
691 | |
if (a == NULL) {
|
692 | |
return -1;
|
693 | |
}
|
694 | |
if (b == NULL) {
|
695 | |
return 1;
|
696 | |
}
|
697 | |
return strcasecmp(a, b);
|
698 | 685 |
}
|
699 | 686 |
|
700 | 687 |
/*
|
|
1815 | 1802 |
bar_height);
|
1816 | 1803 |
|
1817 | 1804 |
/* Set the WM_CLASS and WM_NAME (we don't need UTF-8) atoms */
|
|
1805 |
char *class;
|
|
1806 |
int len = sasprintf(&class, "%s%ci3bar%c", config.bar_id, 0, 0);
|
1818 | 1807 |
xcb_void_cookie_t class_cookie;
|
1819 | 1808 |
class_cookie = xcb_change_property(xcb_connection,
|
1820 | 1809 |
XCB_PROP_MODE_REPLACE,
|
|
1822 | 1811 |
XCB_ATOM_WM_CLASS,
|
1823 | 1812 |
XCB_ATOM_STRING,
|
1824 | 1813 |
8,
|
1825 | |
(strlen("i3bar") + 1) * 2,
|
1826 | |
"i3bar\0i3bar\0");
|
|
1814 |
len,
|
|
1815 |
class);
|
1827 | 1816 |
|
1828 | 1817 |
char *name;
|
1829 | 1818 |
sasprintf(&name, "i3bar for output %s", walk->name);
|
181 | 181 |
ssize_t swrite(int fd, const void *buf, size_t count);
|
182 | 182 |
|
183 | 183 |
/**
|
|
184 |
* Like strcasecmp but considers the case where either string is NULL.
|
|
185 |
*
|
|
186 |
*/
|
|
187 |
int strcasecmp_nullable(const char *a, const char *b);
|
|
188 |
|
|
189 |
/**
|
184 | 190 |
* Build an i3String from an UTF-8 encoded string.
|
185 | 191 |
* Returns the newly-allocated i3String.
|
186 | 192 |
*
|
109 | 109 |
else
|
110 | 110 |
return n;
|
111 | 111 |
}
|
|
112 |
|
|
113 |
/*
|
|
114 |
* Like strcasecmp but considers the case where either string is NULL.
|
|
115 |
*
|
|
116 |
*/
|
|
117 |
int strcasecmp_nullable(const char *a, const char *b) {
|
|
118 |
if (a == b) {
|
|
119 |
return 0;
|
|
120 |
}
|
|
121 |
if (a == NULL) {
|
|
122 |
return -1;
|
|
123 |
}
|
|
124 |
if (b == NULL) {
|
|
125 |
return 1;
|
|
126 |
}
|
|
127 |
return strcasecmp(a, b);
|
|
128 |
}
|
127 | 127 |
else
|
128 | 128 |
TAILQ_INSERT_TAIL(nodes_head, con, nodes);
|
129 | 129 |
}
|
|
130 |
}
|
|
131 |
goto add_to_focus_head;
|
|
132 |
}
|
|
133 |
|
|
134 |
if (parent->type == CT_DOCKAREA) {
|
|
135 |
/* Insert dock client, sorting alphanumerically by class and then
|
|
136 |
* instance name. This makes dock client order deterministic. As a side
|
|
137 |
* effect, bars without a custom bar id will be sorted according to
|
|
138 |
* their declaration order in the config file. See #3491. */
|
|
139 |
current = NULL;
|
|
140 |
TAILQ_FOREACH (loop, nodes_head, nodes) {
|
|
141 |
int result = strcasecmp_nullable(con->window->class_class, loop->window->class_class);
|
|
142 |
if (result == 0) {
|
|
143 |
result = strcasecmp_nullable(con->window->class_instance, loop->window->class_instance);
|
|
144 |
}
|
|
145 |
if (result < 0) {
|
|
146 |
current = loop;
|
|
147 |
break;
|
|
148 |
}
|
|
149 |
}
|
|
150 |
if (current) {
|
|
151 |
TAILQ_INSERT_BEFORE(loop, con, nodes);
|
|
152 |
} else {
|
|
153 |
TAILQ_INSERT_TAIL(nodes_head, con, nodes);
|
130 | 154 |
}
|
131 | 155 |
goto add_to_focus_head;
|
132 | 156 |
}
|