Implement dock-positioning
This commit is contained in:
parent
23a9814090
commit
64f2a7561d
@ -1,3 +1,5 @@
|
||||
- Implement different dock-positions
|
||||
- Hide-on-modifier is now the default behavior
|
||||
- Bugfix: Recover from closed socket
|
||||
|
||||
v0.6
|
||||
|
@ -9,7 +9,7 @@ i3bar - xcb-based status- and ws-bar
|
||||
|
||||
== SYNOPSIS
|
||||
|
||||
*i3bar* [*-s* 'sock_path'] [*-c* 'command'] [*-m*] [*-f* 'font'] [*-V*] [*-h*]
|
||||
*i3bar* [*-s* 'sock_path'] [*-c* 'command'] [*-m*|*-d*['pos']] [*-f* 'font'] [*-V*] [*-h*]
|
||||
|
||||
== OPTIONS
|
||||
|
||||
@ -21,7 +21,12 @@ Execute '<command>' to get 'stdin'. You can also simply pipe into 'stdin', but s
|
||||
|
||||
*-m, --hide*::
|
||||
Hide the bar, when 'mod4' is not pressed. With this, dockmode will not be set, and the bar is out of the way most of the time so you have more room.
|
||||
If *-c* is specified, the childprocess is sent a 'SIGSTOP' on hiding and a 'SIGCONT' on unhiding of the bars
|
||||
If *-c* is specified, the childprocess is sent a 'SIGSTOP' on hiding and a 'SIGCONT' on unhiding of the bars.
|
||||
This is the default behavior of i3bar.
|
||||
|
||||
*-d*['pos']*, --dock*[*=*'pos']::
|
||||
Put i3bar in dockmode. This will reserve some space for it, so it does not overlap other clients.
|
||||
You can specify either *bottom* (default) or *top* as 'pos'.
|
||||
|
||||
*-f, --font* 'font'::
|
||||
Specifies a 'X-core-font' to use. You can choose one with *xfontsel*(1). Defaults to '-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1'.
|
||||
@ -66,11 +71,15 @@ to connect to i3.
|
||||
|
||||
To get a docked bar with some statusinformation, you use
|
||||
|
||||
*i3status | i3bar*
|
||||
*i3status | i3bar --dock*
|
||||
|
||||
If you want it to hide when not needed, you should instead use
|
||||
If you rather have it displayed at the top of the screen, you use
|
||||
|
||||
*i3bar -c i3status -m*
|
||||
*i3status | i3bar --dock=top*
|
||||
|
||||
If you want it to hide when not needed, you should instead simply use
|
||||
|
||||
*i3bar -c i3status*
|
||||
|
||||
== SEE ALSO
|
||||
|
||||
|
@ -3,8 +3,15 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
typedef enum {
|
||||
DOCKPOS_NONE = 0,
|
||||
DOCKPOS_TOP,
|
||||
DOCKPOS_BOT
|
||||
} dockpos_t;
|
||||
|
||||
typedef struct config_t {
|
||||
int hide_on_modifier;
|
||||
dockpos_t dockpos;
|
||||
int verbose;
|
||||
xcb_colors_t *colors;
|
||||
} config_t;
|
||||
|
@ -1,4 +1,4 @@
|
||||
ATOM_DO(ATOM)
|
||||
ATOM_DO(_NET_WM_WINDOW_TYPE)
|
||||
ATOM_DO(_NET_WM_WINDOW_TYPE_DOCK)
|
||||
ATOM_DO(_NET_WM_STRUT_PARTIAL)
|
||||
#undef ATOM_DO
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user