Implement dock-positioning

This commit is contained in:
Axel Wagner
2011-02-21 15:47:58 +01:00
parent 23a9814090
commit 64f2a7561d
6 changed files with 102 additions and 14 deletions

View File

@ -79,10 +79,11 @@ static void free_colors(struct xcb_color_strings_t *colors) {
}
void print_usage(char *elf_name) {
printf("Usage: %s [-s sock_path] [-c command] [-m] [-f font] [-V] [-h]\n", elf_name);
printf("Usage: %s [-s sock_path] [-c command] [-m|-d[pos]] [-f font] [-V] [-h]\n", elf_name);
printf("-s <sock_path>\tConnect to i3 via <sock_path>\n");
printf("-c <command>\tExecute <command> to get stdin\n");
printf("-m\t\tHide the bars, when mod4 is not pressed.\n");
printf("-d[<pos>]\tEnable dockmode. <pos> is \"top\" or \"bottom\". Default is bottom\n");
printf("\t\tIf -c is specified, the childprocess is sent a SIGSTOP on hiding,\n");
printf("\t\tand a SIGCONT on unhiding of the bars\n");
printf("-f <font>\tUse X-Core-Font <font> for display\n");
@ -121,11 +122,13 @@ int main(int argc, char **argv) {
/* Definition of the standard-config */
config.hide_on_modifier = 0;
config.dockpos = DOCKPOS_NONE;
static struct option long_opt[] = {
{ "socket", required_argument, 0, 's' },
{ "command", required_argument, 0, 'c' },
{ "hide", no_argument, 0, 'm' },
{ "dock", optional_argument, 0, 'd' },
{ "font", required_argument, 0, 'f' },
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'v' },
@ -141,7 +144,7 @@ int main(int argc, char **argv) {
{ NULL, 0, 0, 0}
};
while ((opt = getopt_long(argc, argv, "s:c:mf:hvVA:B:C:D:E:F:G:H:", long_opt, &option_index)) != -1) {
while ((opt = getopt_long(argc, argv, "s:c:d::mf:hvVA:B:C:D:E:F:G:H:", long_opt, &option_index)) != -1) {
switch (opt) {
case 's':
socket_path = expand_path(optarg);
@ -152,6 +155,20 @@ int main(int argc, char **argv) {
case 'm':
config.hide_on_modifier = 1;
break;
case 'd':
if (optarg == NULL) {
config.dockpos = DOCKPOS_BOT;
break;
}
if (!strcmp(optarg, "top")) {
config.dockpos = DOCKPOS_TOP;
} else if (!strcmp(optarg, "bottom")) {
config.dockpos = DOCKPOS_BOT;
} else {
print_usage(argv[0]);
exit(EXIT_FAILURE);
}
break;
case 'f':
fontname = strdup(optarg);
break;
@ -205,6 +222,15 @@ int main(int argc, char **argv) {
socket_path = expand_path(i3_default_sock_path);
}
if (config.dockpos != DOCKPOS_NONE) {
if (config.hide_on_modifier) {
ELOG("--dock and --hide are mutually exclusive!\n");
exit(EXIT_FAILURE);
}
} else {
config.hide_on_modifier = 1;
}
main_loop = ev_default_loop(0);
init_colors(&colors);

View File

@ -10,6 +10,7 @@
*/
#include <xcb/xcb.h>
#include <xcb/xproto.h>
#include <xcb/xcb_atom.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -688,15 +689,57 @@ void reconfig_windows() {
/* We want dock-windows (for now). When override_redirect is set, i3 is ignoring
* this one */
xcb_void_cookie_t prop_cookie = xcb_change_property(xcb_connection,
xcb_void_cookie_t dock_cookie = xcb_change_property(xcb_connection,
XCB_PROP_MODE_REPLACE,
walk->bar,
atoms[_NET_WM_WINDOW_TYPE],
atoms[ATOM],
XCB_ATOM_ATOM,
32,
1,
(unsigned char*) &atoms[_NET_WM_WINDOW_TYPE_DOCK]);
/* We need to tell i3, where to reserve space for i3bar */
/* left, right, top, bottom, left_start_y, left_end_y,
* right_start_y, right_end_y, top_start_x, top_end_x, bottom_start_x,
* bottom_end_x */
/* A local struct to save the strut_partial property */
struct {
uint32_t left;
uint32_t right;
uint32_t top;
uint32_t bottom;
uint32_t left_start_y;
uint32_t left_end_y;
uint32_t right_start_y;
uint32_t right_end_y;
uint32_t top_start_x;
uint32_t top_end_x;
uint32_t bottom_start_x;
uint32_t bottom_end_x;
} __attribute__((__packed__)) strut_partial = {0,};
switch (config.dockpos) {
case DOCKPOS_NONE:
break;
case DOCKPOS_TOP:
strut_partial.top = font_height + 6;
strut_partial.top_start_x = walk->rect.x;
strut_partial.top_end_x = walk->rect.x + walk->rect.w;
break;
case DOCKPOS_BOT:
strut_partial.bottom = font_height + 6;
strut_partial.bottom_start_x = walk->rect.x;
strut_partial.bottom_end_x = walk->rect.x + walk->rect.w;
break;
}
xcb_void_cookie_t strut_cookie = xcb_change_property(xcb_connection,
XCB_PROP_MODE_REPLACE,
walk->bar,
atoms[_NET_WM_STRUT_PARTIAL],
XCB_ATOM_CARDINAL,
32,
12,
&strut_partial);
/* We also want a graphics-context for the bars (it defines the properties
* with which we draw to them) */
walk->bargc = xcb_generate_id(xcb_connection);
@ -714,10 +757,11 @@ void reconfig_windows() {
map_cookie = xcb_map_window_checked(xcb_connection, walk->bar);
}
if (xcb_request_failed(win_cookie, "Could not create window") ||
xcb_request_failed(pm_cookie, "Could not create pixmap") ||
xcb_request_failed(prop_cookie, "Could not set dock mode") ||
xcb_request_failed(gc_cookie, "Could not create graphical context") ||
if (xcb_request_failed(win_cookie, "Could not create window") ||
xcb_request_failed(pm_cookie, "Could not create pixmap") ||
xcb_request_failed(dock_cookie, "Could not set dock mode") ||
xcb_request_failed(strut_cookie, "Could not set strut") ||
xcb_request_failed(gc_cookie, "Could not create graphical context") ||
(!config.hide_on_modifier && xcb_request_failed(map_cookie, "Could not map window"))) {
exit(EXIT_FAILURE);
}