Make BAR_BOTTOM a command line option

This commit is contained in:
Georg Reinke 2012-07-24 12:08:02 +02:00
parent d7412803f6
commit 25bf9e9739
3 changed files with 25 additions and 18 deletions

View File

@ -11,8 +11,9 @@ Options
bar accepts a couple of command line switches. bar accepts a couple of command line switches.
``` ```
-h Shows the help and bails out. -h Show the help and bail out.
-p Make the bar permanent. -p Make the bar permanent.
-b Show the bar at the bottom of the screen.
``` ```
Configuration Configuration

38
bar.c
View File

@ -1,3 +1,4 @@
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -36,6 +37,7 @@ static xcb_gcontext_t draw_gc;
static xcb_gcontext_t clear_gc; static xcb_gcontext_t clear_gc;
static xcb_gcontext_t underl_gc; static xcb_gcontext_t underl_gc;
static int bar_width; static int bar_width;
static bool bar_bottom;
static fontset_item_t fontset[FONT_MAX]; static fontset_item_t fontset[FONT_MAX];
static fontset_item_t *sel_font = &fontset[FONT_MAIN]; static fontset_item_t *sel_font = &fontset[FONT_MAIN];
@ -231,6 +233,7 @@ set_ewmh_atoms (xcb_window_t root)
xcb_get_property_reply_t *reply1; xcb_get_property_reply_t *reply1;
xcb_atom_t atoms[5]; xcb_atom_t atoms[5];
int compliance_lvl; int compliance_lvl;
unsigned int v[12] = {0};
cookies[0] = xcb_intern_atom (c, 0, strlen ("_NET_WM_WINDOW_TYPE") , "_NET_WM_WINDOW_TYPE"); cookies[0] = xcb_intern_atom (c, 0, strlen ("_NET_WM_WINDOW_TYPE") , "_NET_WM_WINDOW_TYPE");
cookies[1] = xcb_intern_atom (c, 0, strlen ("_NET_WM_WINDOW_TYPE_DOCK"), "_NET_WM_WINDOW_TYPE_DOCK"); cookies[1] = xcb_intern_atom (c, 0, strlen ("_NET_WM_WINDOW_TYPE_DOCK"), "_NET_WM_WINDOW_TYPE_DOCK");
@ -272,12 +275,15 @@ set_ewmh_atoms (xcb_window_t root)
} }
/* Tell the WM that this space is for the bar */ /* Tell the WM that this space is for the bar */
if (*a == atoms[3]) { if (*a == atoms[3]) {
xcb_change_property (c, XCB_PROP_MODE_REPLACE, win, atoms[3], XCB_ATOM_CARDINAL, 32, 12, if (bar_bottom) {
#if (BAR_BOTTOM == 1) v[3] = BAR_HEIGHT;
(const unsigned []) { 0, 0, 0, BAR_HEIGHT, 0, 0, 0, 0, 0, 0, 0, bar_width } ); v[11] = bar_width;
#else }
(const unsigned []) { 0, 0, BAR_HEIGHT, 0, 0, 0, 0, 0, bar_width, 0, 0, 0 } ); else {
#endif v[2] = BAR_HEIGHT;
v[8] = bar_width;
}
xcb_change_property (c, XCB_PROP_MODE_REPLACE, win, atoms[3], XCB_ATOM_CARDINAL, 32, 12, v);
compliance_lvl++; compliance_lvl++;
} }
} }
@ -292,6 +298,7 @@ init (void)
{ {
xcb_screen_t *scr; xcb_screen_t *scr;
xcb_window_t root; xcb_window_t root;
int y;
/* Connect to X */ /* Connect to X */
c = xcb_connect (NULL, NULL); c = xcb_connect (NULL, NULL);
@ -311,12 +318,11 @@ init (void)
/* Create the main window */ /* Create the main window */
win = xcb_generate_id (c); win = xcb_generate_id (c);
xcb_create_window (c, XCB_COPY_FROM_PARENT, win, root, 0, if (bar_bottom)
#if (BAR_BOTTOM == 1) y = scr->height_in_pixels - BAR_HEIGHT;
scr->height_in_pixels - BAR_HEIGHT, else
#else y = 0;
0, xcb_create_window (c, XCB_COPY_FROM_PARENT, win, root, 0, y,
#endif
bar_width, BAR_HEIGHT, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, scr->root_visual, bar_width, BAR_HEIGHT, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, scr->root_visual,
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, (const unsigned []){ palette[0], XCB_EVENT_MASK_EXPOSURE }); XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, (const unsigned []){ palette[0], XCB_EVENT_MASK_EXPOSURE });
@ -380,14 +386,16 @@ main (int argc, char **argv)
int permanent = 0; int permanent = 0;
char ch; char ch;
while ((ch = getopt (argc, argv, "ph")) != -1) { while ((ch = getopt (argc, argv, "phb")) != -1) {
switch (ch) { switch (ch) {
case 'h': case 'h':
printf ("usage: %s [-p | -h]\n" printf ("usage: %s [-p | -h] [-b]\n"
"\t-h Shows this help\n" "\t-h Show this help\n"
"\t-b Put bar at the bottom of the screen\n"
"\t-p Don't close after the data ends\n", argv[0]); "\t-p Don't close after the data ends\n", argv[0]);
exit (0); exit (0);
case 'p': permanent = 1; break; case 'p': permanent = 1; break;
case 'b': bar_bottom = 1; break;
} }
} }

View File

@ -2,8 +2,6 @@
#define BAR_HEIGHT 18 #define BAR_HEIGHT 18
/* The thickness of the underline (in pixels) */ /* The thickness of the underline (in pixels) */
#define BAR_UNDERLINE_HEIGHT 2 #define BAR_UNDERLINE_HEIGHT 2
/* Whether to put the bar at the screen bottom or not */
#define BAR_BOTTOM 0
/* The font used for the bar */ /* The font used for the bar */
#define BAR_MAIN_FONT "-*-terminus-medium-r-normal-*-12-*-*-*-c-*-*-1" #define BAR_MAIN_FONT "-*-terminus-medium-r-normal-*-12-*-*-*-c-*-*-1"
#define BAR_FALLBACK_FONT "fixed" #define BAR_FALLBACK_FONT "fixed"