Allow multiple freespace items (fixes issue #607)

This commit is contained in:
o9000 2016-10-08 10:12:20 +02:00
parent d45af83eaa
commit f8ceb5a849
6 changed files with 51 additions and 29 deletions

View file

@ -323,7 +323,7 @@ panel_gradient_id = 5
* `S` shows the Systray (also called notification area)
* `B` shows the Battery status
* `C` shows the Clock
* `F` adds an extensible spacer (freespace). Has no effect if `T` is also present. *(since 0.12)*
* `F` adds an extensible spacer (freespace). You can specify more than one. Has no effect if `T` is also present. *(since 0.12)*
* `E` adds an executor plugin. You can specify more than one. *(since 0.12.4)*
* `:` adds a separator. You can specify more than one. *(since 0.13.0)*

View file

@ -33,28 +33,49 @@
void init_freespace_panel(void *p)
{
Panel *panel = (Panel *)p;
FreeSpace *freespace = &panel->freespace;
if (!freespace->area.bg)
freespace->area.bg = &g_array_index(backgrounds, Background, 0);
freespace->area.parent = p;
freespace->area.panel = p;
snprintf(freespace->area.name, sizeof(freespace->area.name), "Freespace");
freespace->area.size_mode = LAYOUT_FIXED;
freespace->area.resize_needed = 1;
freespace->area.on_screen = TRUE;
freespace->area._resize = resize_freespace;
// Make sure this is only done once if there are multiple items
if (panel->freespace_list)
return;
for (size_t k = 0; k < strlen(panel_items_order); k++) {
if (panel_items_order[k] == 'F') {
FreeSpace *freespace = (FreeSpace *) calloc(1, sizeof(FreeSpace));
panel->freespace_list = g_list_append(panel->freespace_list, freespace);
if (!freespace->area.bg)
freespace->area.bg = &g_array_index(backgrounds, Background, 0);
freespace->area.parent = p;
freespace->area.panel = p;
snprintf(freespace->area.name, sizeof(freespace->area.name), "Freespace");
freespace->area.size_mode = LAYOUT_FIXED;
freespace->area.resize_needed = 1;
freespace->area.on_screen = TRUE;
freespace->area._resize = resize_freespace;
}
}
}
void cleanup_freespace(Panel *panel)
{
if (panel->freespace_list)
g_list_free_full(panel->freespace_list, free);
panel->freespace_list = NULL;
}
int freespace_get_max_size(Panel *p)
{
// Get space used by every element except the freespace
int size = 0;
int spacers = 0;
for (GList *walk = p->area.children; walk; walk = g_list_next(walk)) {
Area *a = (Area *)walk->data;
if (a->_resize == resize_freespace || !a->on_screen)
if (!a->on_screen)
continue;
if (a->_resize == resize_freespace) {
spacers++;
continue;
}
if (panel_horizontal)
size += a->width + p->area.paddingx;
@ -67,7 +88,7 @@ int freespace_get_max_size(Panel *p)
else
size = p->area.height - size - top_bottom_border_width(&p->area) - p->area.paddingxlr;
return size;
return size / spacers;
}
gboolean resize_freespace(void *obj)

View file

@ -12,7 +12,9 @@ typedef struct FreeSpace {
Area area;
} FreeSpace;
void cleanup_freespace();
struct Panel;
void cleanup_freespace(struct Panel *panel);
void init_freespace_panel(void *panel);
gboolean resize_freespace(void *obj);

View file

@ -131,6 +131,8 @@ void cleanup_panel()
for (int i = 0; i < num_panels; i++) {
Panel *p = &panels[i];
cleanup_freespace(p);
free_area(&p->area);
if (p->temp_pmap)
XFreePixmap(server.display, p->temp_pmap);
@ -495,8 +497,8 @@ gboolean resize_panel(void *obj)
}
}
}
if (panel->freespace.area.on_screen)
resize_freespace(&panel->freespace);
for (GList *l = panel->freespace_list; l; l = g_list_next(l))
resize_freespace(l->data);
return FALSE;
}
@ -574,6 +576,7 @@ void set_panel_items_order(Panel *p)
int i_execp = 0;
int i_separator = 0;
int i_freespace = 0;
for (int k = 0; k < strlen(panel_items_order); k++) {
if (panel_items_order[k] == 'L') {
p->area.children = g_list_append(p->area.children, &p->launcher);
@ -593,8 +596,12 @@ void set_panel_items_order(Panel *p)
}
if (panel_items_order[k] == 'C')
p->area.children = g_list_append(p->area.children, &p->clock);
if (panel_items_order[k] == 'F')
p->area.children = g_list_append(p->area.children, &p->freespace);
if (panel_items_order[k] == 'F') {
GList *item = g_list_nth(p->freespace_list, i_freespace);
i_freespace++;
if (item)
p->area.children = g_list_append(p->area.children, (Area *)item->data);
}
if (panel_items_order[k] == ':') {
GList *item = g_list_nth(p->separator_list, i_separator);
i_separator++;

View file

@ -128,7 +128,7 @@ typedef struct Panel {
#endif
Launcher launcher;
FreeSpace freespace;
GList *freespace_list;
GList *separator_list;
GList *execp_list;

View file

@ -2117,7 +2117,7 @@ void panel_add_item(GtkWidget *widget, gpointer data)
itemsColValue, &value,
-1);
if (!panel_contains(value) || g_str_equal(value, ":")) {
if (!panel_contains(value) || g_str_equal(value, ":") || g_str_equal(value, "E") || g_str_equal(value, "F")) {
GtkTreeIter iter;
gtk_list_store_append(panel_items, &iter);
gtk_list_store_set(panel_items, &iter,
@ -2126,15 +2126,7 @@ void panel_add_item(GtkWidget *widget, gpointer data)
-1);
if (g_str_equal(value, ":")) {
separator_create_new();
}
} else if (!panel_contains(value) || g_str_equal(value, "E")) {
GtkTreeIter iter;
gtk_list_store_append(panel_items, &iter);
gtk_list_store_set(panel_items, &iter,
itemsColName, g_strdup(name),
itemsColValue, g_strdup(value),
-1);
if (g_str_equal(value, "E")) {
} else if (g_str_equal(value, "E")) {
execp_create_new();
}
}