fixed switch between config with killall -SIGUSR1 tint2

git-svn-id: http://tint2.googlecode.com/svn/trunk@226 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
lorthiois@bbsoft.fr 2009-10-23 20:23:11 +00:00
parent 1f42a6b80d
commit 8847de07c1
5 changed files with 65 additions and 69 deletions

View file

@ -74,10 +74,6 @@ static GSList *list_back;
void init_config()
{
// get monitor and desktop config
get_monitors();
get_desktops();
// append full transparency background
list_back = g_slist_append(0, calloc(1, sizeof(Area)));
@ -283,13 +279,18 @@ void add_entry (char *key, char *value)
b[0] = '\0';
panel_config.pourcentx = 1;
}
panel_config.initial_width = atof(value1);
panel_config.area.width = atoi(value1);
if (panel_config.area.width == 0) {
// full width mode
panel_config.area.width = 100;
panel_config.pourcentx = 1;
}
if (value2) {
if ((b = strchr (value2, '%'))) {
b[0] = '\0';
panel_config.pourcenty = 1;
}
panel_config.initial_height = atof(value2);
panel_config.area.height = atoi(value2);
}
}
else if (strcmp (key, "panel_margin") == 0) {
@ -867,7 +868,7 @@ void save_config ()
FILE *fp;
if (old_task_icon_size) {
panel_config.g_task.area.paddingy = ((int)panel_config.initial_height - (2 * panel_config.area.paddingy) - old_task_icon_size) / 2;
panel_config.g_task.area.paddingy = ((int)panel_config.area.height - (2 * panel_config.area.paddingy) - old_task_icon_size) / 2;
}
dir = g_build_filename (g_get_user_config_dir(), "tint2", NULL);
@ -907,7 +908,7 @@ void save_config ()
if (panel_position & LEFT) fputs(" left horizontal\n", fp);
else if (panel_position & RIGHT) fputs(" right horizontal\n", fp);
else fputs(" center horizontal\n", fp);
fprintf(fp, "panel_size = %d %d\n", (int)panel_config.initial_width, (int)panel_config.initial_height);
fprintf(fp, "panel_size = %d %d\n", panel_config.area.width, panel_config.area.height);
fprintf(fp, "panel_margin = %d %d\n", panel_config.marginx, panel_config.marginy);
fprintf(fp, "panel_padding = %d %d %d\n", panel_config.area.paddingxlr, panel_config.area.paddingy, panel_config.area.paddingx);
fprintf(fp, "font_shadow = %d\n", panel_config.g_task.font_shadow);

View file

@ -139,33 +139,26 @@ void init_panel()
p->area.list = g_slist_append(p->area.list, &systray);
}
// full width mode
if (!p->initial_width) {
p->initial_width = 100;
p->pourcentx = 1;
}
if (i >= old_nb_panel) {
// new panel
//printf("new panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height);
// Catch some events
// new panel : catch some events
long event_mask = ExposureMask|ButtonPressMask|ButtonReleaseMask;
if (g_tooltip.enabled)
event_mask |= PointerMotionMask|LeaveWindowMask;
XSetWindowAttributes att = { ParentRelative, 0L, 0, 0L, 0, 0, Always, 0L, 0L, False, event_mask, NoEventMask, False, 0, 0 };
if (p->main_win) XDestroyWindow(server.dsp, p->main_win);
p->main_win = XCreateWindow(server.dsp, server.root_win, p->posx, p->posy, p->area.width, p->area.height, 0, server.depth, InputOutput, CopyFromParent, CWEventMask, &att);
set_panel_properties(p);
set_panel_background(p);
XMapWindow (server.dsp, p->main_win);
}
else {
// old panel
//printf("old panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height);
XMoveResizeWindow(server.dsp, p->main_win, p->posx, p->posy, p->area.width, p->area.height);
set_panel_background(p);
}
//printf("panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height);
set_panel_properties(p);
set_panel_background(p);
if (i >= old_nb_panel) {
// map new panel
XMapWindow (server.dsp, p->main_win);
}
}
@ -183,25 +176,22 @@ void init_panel_size_and_position(Panel *panel)
// detect panel size
if (panel_horizontal) {
if (panel->pourcentx)
panel->area.width = (float)server.monitor[panel->monitor].width * panel->initial_width / 100;
else
panel->area.width = panel->initial_width;
panel->area.width = (float)server.monitor[panel->monitor].width * panel->area.width / 100;
if (panel->pourcenty)
panel->area.height = (float)server.monitor[panel->monitor].height * panel->initial_height / 100;
else
panel->area.height = panel->initial_height;
panel->area.height = (float)server.monitor[panel->monitor].height * panel->area.height / 100;
if (panel->area.pix.border.rounded > panel->area.height/2)
panel->area.pix.border.rounded = panel->area.height/2;
}
else {
int old_panel_height = panel->area.height;
if (panel->pourcentx)
panel->area.height = (float)server.monitor[panel->monitor].height * panel->initial_width / 100;
panel->area.height = (float)server.monitor[panel->monitor].height * panel->area.width / 100;
else
panel->area.height = panel->initial_width;
panel->area.height = panel->area.width;
if (panel->pourcenty)
panel->area.width = (float)server.monitor[panel->monitor].width * panel->initial_height / 100;
panel->area.width = (float)server.monitor[panel->monitor].width * old_panel_height / 100;
else
panel->area.width = panel->initial_height;
panel->area.width = old_panel_height;
if (panel->area.pix.border.rounded > panel->area.width/2)
panel->area.pix.border.rounded = panel->area.width/2;
}
@ -390,6 +380,38 @@ void set_panel_properties(Panel *p)
long val = server.atom._NET_WM_WINDOW_TYPE_DOCK;
XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_WINDOW_TYPE, XA_ATOM, 32, PropModeReplace, (unsigned char *) &val, 1);
// Sticky and below other window
val = 0xFFFFFFFF;
XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_DESKTOP, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &val, 1);
Atom state[4];
state[0] = server.atom._NET_WM_STATE_SKIP_PAGER;
state[1] = server.atom._NET_WM_STATE_SKIP_TASKBAR;
state[2] = server.atom._NET_WM_STATE_STICKY;
state[3] = server.atom._NET_WM_STATE_BELOW;
XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (unsigned char *) state, 4);
// Unfocusable
XWMHints wmhints;
if (panel_dock) {
// TODO: Xdnd feature cannot be used in withdrawn state at the moment (at least GTK apps fail, qt seems to work)
wmhints.icon_window = wmhints.window_group = p->main_win;
wmhints.flags = StateHint | IconWindowHint;
wmhints.initial_state = WithdrawnState;
}
else {
wmhints.flags = InputHint;
wmhints.input = False;
}
XSetWMHints(server.dsp, p->main_win, &wmhints);
// Undecorated
long prop[5] = { 2, 0, 0, 0, 0 };
XChangeProperty(server.dsp, p->main_win, server.atom._MOTIF_WM_HINTS, server.atom._MOTIF_WM_HINTS, 32, PropModeReplace, (unsigned char *) prop, 5);
// XdndAware - Register for Xdnd events
int version=5;
XChangeProperty(server.dsp, p->main_win, server.atom.XdndAware, XA_ATOM, 32, PropModeReplace, (unsigned char*)&version, 1);
// Reserved space
long struts [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
if (panel_horizontal) {
@ -424,44 +446,13 @@ void set_panel_properties(Panel *p)
XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STRUT, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 4);
XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STRUT_PARTIAL, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 12);
// Sticky and below other window
val = 0xFFFFFFFF;
XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_DESKTOP, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &val, 1);
Atom state[4];
state[0] = server.atom._NET_WM_STATE_SKIP_PAGER;
state[1] = server.atom._NET_WM_STATE_SKIP_TASKBAR;
state[2] = server.atom._NET_WM_STATE_STICKY;
state[3] = server.atom._NET_WM_STATE_BELOW;
XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (unsigned char *) state, 4);
// Fixed position and non-resizable window
// Allow panel move and resize when tint2 reload config file
XSizeHints size_hints;
size_hints.flags = PPosition|PMinSize|PMaxSize;
size_hints.min_width = size_hints.max_width = p->area.width;
size_hints.min_height = size_hints.max_height = p->area.height;
XSetWMNormalHints(server.dsp, p->main_win, &size_hints);
// Unfocusable
XWMHints wmhints;
if (panel_dock) {
// TODO: Xdnd feature cannot be used in withdrawn state at the moment (at least GTK apps fail, qt seems to work)
wmhints.icon_window = wmhints.window_group = p->main_win;
wmhints.flags = StateHint | IconWindowHint;
wmhints.initial_state = WithdrawnState;
}
else {
wmhints.flags = InputHint;
wmhints.input = False;
}
XSetWMHints(server.dsp, p->main_win, &wmhints);
// Undecorated
long prop[5] = { 2, 0, 0, 0, 0 };
XChangeProperty(server.dsp, p->main_win, server.atom._MOTIF_WM_HINTS, server.atom._MOTIF_WM_HINTS, 32, PropModeReplace, (unsigned char *) prop, 5);
// XdndAware - Register for Xdnd events
int version=5;
XChangeProperty(server.dsp, p->main_win, server.atom.XdndAware, XA_ATOM, 32, PropModeReplace, (unsigned char*)&version, 1);
}

View file

@ -71,7 +71,6 @@ typedef struct {
// position relative to root window
int posx, posy;
int marginx, marginy;
float initial_width, initial_height;
int pourcentx, pourcenty;
// location of the panel (monitor number)
int monitor;

View file

@ -115,6 +115,10 @@ void init (int argc, char *argv[])
default_icon = imlib_load_image(path);
g_free(path);
}
// get monitor and desktop config
get_monitors();
get_desktops();
}
@ -859,11 +863,12 @@ int main (int argc, char *argv[])
event_timer();
switch (signal_pending) {
case SIGUSR1:
case SIGUSR1: // reload config file
signal_pending = 0;
init_config();
config_read_file (config_path);
init_panel();
cleanup_config();
break;
case SIGINT:
case SIGTERM:

View file

@ -129,7 +129,7 @@ int main (int argc, char ** argv)
// define main layout : container, menubar, toolbar, themeView
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), _("Tint2 theme"));
gtk_window_set_title(GTK_WINDOW(window), _("Panel theming"));
gtk_window_set_default_size(GTK_WINDOW(window), 600, 350);
g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (menuQuit), NULL);
vBox = gtk_vbox_new (FALSE, 0);