Conf/Systray: add [systray] section

This commit is contained in:
Martin Duquesnoy 2010-07-23 14:36:05 +02:00
parent 4cf2b8bf8f
commit 461b45545a
7 changed files with 92 additions and 28 deletions

View File

@ -462,28 +462,28 @@ conf_tag_section(void)
conf.border.tag = fetch_opt_first(sec, "false", "border").bool;
conf.tagautohide = fetch_opt_first(sec, "false", "autohide").bool;
conf.tagnamecount = fetch_opt_first(sec, "false", "name_count").bool;
def_tag = fetch_section_first(sec, "default_tag");
position = fetch_opt_first(def_tag, "top", "infobar_position").str;
if(!strcmp(position, "none")
|| !strcmp(position, "hide")
if(!strcmp(position, "none")
|| !strcmp(position, "hide")
|| !strcmp(position, "hidden"))
bar_pos = IB_Hide;
else if(!strcmp(position, "bottom")
else if(!strcmp(position, "bottom")
|| !strcmp(position, "down"))
bar_pos = IB_Bottom;
else
bar_pos = IB_Top;
/* If there is no tag in the conf or more than
* MAXTAG (36) print an error and create only one.
*/
Tag default_tag = { fetch_opt_first(def_tag, "new tag", "name").str, NULL, 0, 1,
fetch_opt_first(def_tag, "0.5", "mwfact").fnum,
fetch_opt_first(def_tag, "1", "nmaster").num,
False, fetch_opt_first(def_tag, "false", "resizehint").bool,
fetch_opt_first(def_tag, "0.5", "mwfact").fnum,
fetch_opt_first(def_tag, "1", "nmaster").num,
False, fetch_opt_first(def_tag, "false", "resizehint").bool,
False, False, bar_pos,
layout_name_to_struct(conf.layout, fetch_opt_first(def_tag, "title_right", "layout").str, conf.nlayout, layout_list),
0, NULL, 0 };
@ -719,6 +719,26 @@ conf_keybind_section(void)
return;
}
void
conf_systray_section(void)
{
struct conf_sec *systray;
int sc = screen_count();
systray = fetch_section_first(NULL, "systray");
conf.systray.active = fetch_opt_first(systray, "true", "active").bool;
if((conf.systray.screen = fetch_opt_first(systray, "0", "screen").num) < 0
|| conf.systray.screen >= sc)
conf.systray.screen = 0;
if((conf.systray.spacing = fetch_opt_first(systray, "3", "spacing").num) < 0)
conf.systray.spacing = 0;
return;
}
/** Configuration initialization
*/
void
@ -747,6 +767,7 @@ init_conf(void)
conf_menu_section();
conf_launcher_section();
conf_keybind_section();
conf_systray_section();
print_unused(NULL);

View File

@ -61,7 +61,7 @@ draw_text(Drawable d, int x, int y, char* fg, int pad, char *str)
{
ni = parse_image_block(im, str);
if(d == infobar[0 /* SYSTRAY_SCREEN */].bar->dr)
if(infobar[conf.systray.screen].bar && d == infobar[conf.systray.screen].bar->dr)
sw = systray_get_width();
for(i = 0; i < ni; ++i)

View File

@ -520,7 +520,7 @@ fetch_section_first(struct conf_sec *s, char *name)
if (!s)
{
TAILQ_FOREACH(sec, &config, entry)
if (!strcmp(sec->name, name)) {
if(sec->name && !strcmp(sec->name, name)) {
ret = sec;
break;
}
@ -528,7 +528,7 @@ fetch_section_first(struct conf_sec *s, char *name)
else
{
TAILQ_FOREACH(sec, &s->sub, entry)
if (!strcmp(sec->name, name)) {
if (sec->name && !strcmp(sec->name, name)) {
ret = sec;
break;
}

View File

@ -143,8 +143,7 @@ statustext_normal(int sc, char *str)
char col[8] = { 0 };
int n, i, j, k, sw = 0;
/* if(sc == SYSTRAY_SCREEN) */
if(!sc)
if(sc == conf.systray.screen)
sw = systray_get_width();
for(i = j = n = 0; i < strlen(str); ++i, ++j)
@ -205,11 +204,9 @@ statustext_handle(int sc, char *str)
if(!str)
return;
/* if(sc == SYSTRAY_SCREEN) */
if(!sc)
if(sc == conf.systray.screen)
sw = systray_get_width();
barwin_refresh_color(infobar[sc].bar);
/* save last status text address (for free at the end) */

View File

@ -445,6 +445,12 @@ typedef struct
Bool tag;
Bool layout;
} border;
struct
{
Bool active;
int screen;
int spacing;
} systray;
Alias alias[256];
uint mouse_tag_action[TagActionLast];
Layout layout[NUM_OF_LAYOUT];

View File

@ -32,14 +32,16 @@
#include "wmfs.h"
#define TRAY_SPACING (3)
#define TRAY_DWIDTH (infobar[0].bar->geo.height + TRAY_SPACING)
#define TRAY_DWIDTH (infobar[conf.systray.screen].bar->geo.height + conf.systray.spacing)
Bool
systray_acquire(void)
{
char systray_atom[32];
if(!conf.systray.active)
return False;
snprintf(systray_atom, sizeof(systray_atom), "_NET_SYSTEM_TRAY_S%u", SCREEN);
trayatom = XInternAtom(dpy, systray_atom, False);
@ -58,12 +60,15 @@ systray_init(void)
{
XSetWindowAttributes wattr;
if(!conf.systray.active)
return;
/* Init traywin window */
wattr.event_mask = ButtonPressMask|ExposureMask;
wattr.override_redirect = True;
wattr.background_pixel = conf.colors.bar;
traywin = XCreateSimpleWindow(dpy, infobar[0].bar->win, 0, 0, 1, 1, 0, 0, conf.colors.bar);
traywin = XCreateSimpleWindow(dpy, infobar[conf.systray.screen].bar->win, 0, 0, 1, 1, 0, 0, conf.colors.bar);
XChangeWindowAttributes(dpy, traywin, CWEventMask | CWOverrideRedirect | CWBackPixel, &wattr);
XSelectInput(dpy, traywin, KeyPressMask | ButtonPressMask);
@ -80,6 +85,9 @@ systray_init(void)
void
systray_kill(void)
{
if(!conf.systray.active)
return;
XSetSelectionOwner(dpy, trayatom, None, CurrentTime);
XUnmapWindow(dpy, traywin);
@ -89,11 +97,15 @@ systray_kill(void)
void
systray_add(Window win)
{
Systray *s = emalloc(1, sizeof(Systray));
Systray *s;
if(!conf.systray.active)
return;
s = emalloc(1, sizeof(Systray));
s->win = win;
s->geo.height = infobar[0].bar->geo.height;
s->geo.height = infobar[conf.systray.screen].bar->geo.height;
s->geo.width = TRAY_DWIDTH;
setwinstate(s->win, WithdrawnState);
@ -117,6 +129,9 @@ systray_del(Systray *s)
{
Systray **ss;
if(!conf.systray.active)
return;
for(ss = &trayicons; *ss && *ss != s; ss = &(*ss)->next);
*ss = s->next;
@ -131,7 +146,7 @@ systray_configure(Systray *s)
long d = 0;
XSizeHints *sh = NULL;
if(!(sh = XAllocSizeHints()))
if(!(sh = XAllocSizeHints()) || !conf.systray.active)
return;
XGetWMNormalHints(dpy, s->win, sh, &d);
@ -152,7 +167,7 @@ systray_state(Systray *s)
long flags;
int code = 0;
if(!(flags = ewmh_get_xembed_state(s->win)))
if(!(flags = ewmh_get_xembed_state(s->win)) || !conf.systray.active)
return;
if(flags & XEMBED_MAPPED)
@ -178,6 +193,9 @@ systray_freeicons(void)
{
Systray *i, *next;
if(!conf.systray.active)
return;
for(i = trayicons; i; i = next)
{
next = i->next;
@ -195,6 +213,10 @@ systray_find(Window win)
{
Systray *i;
if(!conf.systray.active)
return NULL;
for(i = trayicons; i; i = i->next)
if(i->win == win)
return i;
@ -208,8 +230,11 @@ systray_get_width(void)
int w = 0;
Systray *i;
if(!conf.systray.active)
return 0;
for(i = trayicons; i; i = i->next)
w += i->geo.width + TRAY_SPACING + 1;
w += i->geo.width + conf.systray.spacing + 1;
return w;
}
@ -221,9 +246,12 @@ systray_update(void)
XWindowAttributes xa;
int x = 1;
if(!conf.systray.active)
return;
if(!trayicons)
{
XMoveResizeWindow(dpy, traywin, infobar[0].bar->geo.width - 1, 0, 1, 1);
XMoveResizeWindow(dpy, traywin, infobar[conf.systray.screen].bar->geo.width - 1, 0, 1, 1);
return;
}
@ -237,15 +265,16 @@ systray_update(void)
if(xa.width < (i->geo.width = TRAY_DWIDTH))
i->geo.width = xa.width;
if(xa.height < (i->geo.height = infobar[0].bar->geo.height))
if(xa.height < (i->geo.height = infobar[conf.systray.screen].bar->geo.height))
i->geo.height = xa.height;
XMoveResizeWindow(dpy, i->win, (i->geo.x = x), 0, i->geo.width, i->geo.height);
x += i->geo.width + TRAY_SPACING;
x += i->geo.width + conf.systray.spacing;
}
XMoveResizeWindow(dpy, traywin, infobar[0].bar->geo.width - x, 0, x, infobar[0].bar->geo.height);
XMoveResizeWindow(dpy, traywin, infobar[conf.systray.screen].bar->geo.width - x,
0, x, infobar[conf.systray.screen].bar->geo.height);
return;
}

View File

@ -35,6 +35,17 @@
[/bar]
[systray]
# Enable/disable systray
active = true
# Screen of systray
screen = 0
# Spacing between tray icons
spacing = 3
[/systray]
[layouts]
fg = "#191919"
bg = "#7E89A2"