Commit 6304715d authored by Oskari Rauta's avatar Oskari Rauta Committed by o9000

Add separator plugin

parent 7dbc894d
......@@ -87,6 +87,7 @@ include_directories( ${PROJECT_BINARY_DIR}
src/util
src/execplugin
src/freespace
src/separator
${X11_INCLUDE_DIRS}
${PANGOCAIRO_INCLUDE_DIRS}
${PANGO_INCLUDE_DIRS}
......@@ -114,6 +115,7 @@ set( SOURCES src/config.c
src/tooltip/tooltip.c
src/execplugin/execplugin.c
src/freespace/freespace.c
src/separator/separator.c
src/util/area.c
src/util/common.c
src/util/strnatcmp.c
......
......@@ -51,6 +51,7 @@
#include "window.h"
#include "tooltip.h"
#include "timer.h"
#include "separator.h"
#include "execplugin.h"
#ifdef ENABLE_BATTERY
......@@ -201,6 +202,15 @@ void load_launcher_app_dir(const char *path)
g_list_free(files);
}
Separator *get_or_create_last_separator()
{
if (!panel_config.separator_list) {
fprintf(stderr, "Warning: separator items should shart with 'separator = new'\n");
panel_config.separator_list = g_list_append(panel_config.separator_list, create_separator());
}
return (Separator *)g_list_last(panel_config.separator_list)->data;
}
Execp *get_or_create_last_execp()
{
if (!panel_config.execp_list) {
......@@ -526,6 +536,22 @@ void add_entry(char *key, char *value)
#endif
}
/* Separator */
else if (strcmp(key, "separator") == 0) {
panel_config.separator_list = g_list_append(panel_config.separator_list, create_separator());
} else if (strcmp(key, "separator_color") == 0) {
Separator *separator = get_or_create_last_separator();
extract_values(value, &value1, &value2, &value3);
get_color(value1, separator->color.rgb);
if (value2)
separator->color.alpha = (atoi(value2) / 100.0);
else
separator->color.alpha = 0.5;
} else if (strcmp(key, "separator_style") == 0) {
Separator *separator = get_or_create_last_separator();
separator->style = atoi(value);
}
/* Execp */
else if (strcmp(key, "execp") == 0) {
panel_config.execp_list = g_list_append(panel_config.execp_list, create_execp());
......
......@@ -171,6 +171,7 @@ void init_panel()
init_battery();
#endif
init_taskbar();
init_separator();
init_execp();
// number of panels (one monitor or 'all' monitors)
......@@ -204,6 +205,7 @@ void init_panel()
p->area.size_mode = LAYOUT_DYNAMIC;
p->area._resize = resize_panel;
p->area._clear = panel_clear_background;
p->separator_list = NULL;
init_panel_size_and_position(p);
// add children according to panel_items
for (int k = 0; k < strlen(panel_items_order); k++) {
......@@ -223,6 +225,8 @@ void init_panel()
init_clock_panel(p);
if (panel_items_order[k] == 'F' && !strstr(panel_items_order, "T"))
init_freespace_panel(p);
if (panel_items_order[k] == ':')
init_separator_panel(p);
if (panel_items_order[k] == 'E')
init_execp_panel(p);
}
......@@ -552,6 +556,7 @@ void set_panel_items_order(Panel *p)
}
int i_execp = 0;
int i_separator = 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);
......@@ -573,6 +578,12 @@ void set_panel_items_order(Panel *p)
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] == ':') {
GList *item = g_list_nth(p->separator_list, i_separator);
i_separator++;
if (item)
p->area.children = g_list_append(p->area.children, (Area *)item->data);
}
if (panel_items_order[k] == 'E') {
GList *item = g_list_nth(p->execp_list, i_execp);
i_execp++;
......
......@@ -22,6 +22,7 @@
#include "launcher.h"
#include "freespace.h"
#include "execplugin.h"
#include "separator.h"
#ifdef ENABLE_BATTERY
#include "battery.h"
......@@ -127,6 +128,7 @@ typedef struct Panel {
Launcher launcher;
FreeSpace freespace;
GList *separator_list;
GList *execp_list;
// Autohide
......
// Tint2 : Separator plugin
// Author: Oskari Rauta
#include <string.h>
#include <stdio.h>
#include <cairo.h>
#include <cairo-xlib.h>
#include <pango/pangocairo.h>
#include <stdlib.h>
#include <math.h>
#include "window.h"
#include "server.h"
#include "panel.h"
#include "common.h"
#include "separator.h"
Separator *create_separator()
{
Separator *separator = calloc(1, sizeof(Separator));
return separator;
}
void destroy_separator(void *obj)
{
Separator *separator = (Separator *)obj;
remove_area(&separator->area);
free_area(&separator->area);
free_and_null(separator);
}
void init_separator()
{
GList *to_remove = panel_config.separator_list;
for (int k = 0; k < strlen(panel_items_order) && to_remove; k++) {
if (panel_items_order[k] == ':') {
to_remove = to_remove->next;
}
}
if (to_remove) {
if (to_remove == panel_config.separator_list) {
g_list_free_full(to_remove, destroy_separator);
panel_config.separator_list = NULL;
} else {
// Cut panel_config.separator_list
if (to_remove->prev)
to_remove->prev->next = NULL;
to_remove->prev = NULL;
// Remove all elements of to_remove and to_remove itself
g_list_free_full(to_remove, destroy_separator);
}
}
}
void init_separator_panel(void *p)
{
Panel *panel = (Panel *)p;
// Make sure this is only done once if there are multiple items
if (panel->separator_list)
return;
// panel->separator_list is now a copy of the pointer panel_config.separator_list
// We make it a deep copy
panel->separator_list = g_list_copy_deep(panel_config.separator_list, NULL, NULL);
for (GList *l = panel->separator_list; l; l = l->next) {
Separator *separator = l->data;
if (!separator->area.bg)
separator->area.bg = &g_array_index(backgrounds, Background, 0);
separator->area.parent = p;
separator->area.panel = p;
snprintf(separator->area.name, sizeof(separator->area.name), "separator");
separator->area.size_mode = LAYOUT_FIXED;
separator->area.resize_needed = 1;
separator->area.on_screen = TRUE;
separator->area._resize = resize_separator;
separator->area._draw_foreground = draw_separator;
}
}
void cleanup_separator()
{
// Cleanup frontends
for (int i = 0; i < num_panels; i++) {
g_list_free_full(panels[i].separator_list, destroy_separator);
panels[i].separator_list = NULL;
}
// Cleanup backends
g_list_free_full(panel_config.separator_list, destroy_separator);
panel_config.separator_list = NULL;
}
gboolean resize_separator(void *obj)
{
Separator *separator = obj;
// Panel *panel = separator->area.panel;
if (!separator->area.on_screen)
return FALSE;
double d_height = panel_horizontal ? separator->area.height : separator->area.width;
double d_thickness = round(d_height / 16) >= 1.0 ? round(d_height / 16) : 1.0;
if (separator->style == 3)
d_thickness = round(d_height / 8) >= 1.0 ? round(d_height / 8) : 1.0;
double d_len = round(d_height / 16) >= 1.0 ? round(d_height / 16) : 1.0;
double d_width = d_thickness * 5;
if (separator->style == 4) {
d_width = d_thickness * 7;
d_thickness = d_thickness * 3;
}
if (separator->style == 2) {
d_width = d_height;
d_thickness = round(d_height / 8) >= 1.0 ? round(d_height / 8) : 1.0;
d_len = d_thickness;
}
double d_empty_thickness = d_thickness;
if (separator->style == 5 || separator->style == 6) {
d_width = (d_thickness * 4) + 2.0;
d_thickness = 1.0;
}
if (panel_horizontal) {
separator->area.width = d_width;
separator->area.height = d_height;
} else {
separator->area.width = d_height;
separator->area.height = d_width;
}
separator->empty_thickness = d_empty_thickness;
separator->thickness = d_thickness;
separator->len = d_len;
schedule_redraw(&separator->area);
panel_refresh = TRUE;
return TRUE;
}
void draw_separator(void *obj, cairo_t *c)
{
Separator *separator = obj;
if (separator->style == 0 )
return;
double start_point = 0 + ( separator->thickness * 2 );
double end_point = separator->area.height - ( separator->thickness * 2 );
if (!panel_horizontal)
end_point = separator->area.width - ( separator->thickness * 2 );
double count = end_point - start_point;
double thickness = separator->thickness;
double len = separator->len;
int alt = 0;
double x_fix = 0;
if (separator->style == 2) {
if (!panel_horizontal)
start_point=start_point + 2;
cairo_set_source_rgba(c, separator->color.rgb[0], separator->color.rgb[1], separator->color.rgb[2], separator->color.alpha);
cairo_set_line_width(c, 1);
cairo_rectangle(c, start_point - 2, start_point - (panel_horizontal ? 0 : 4), end_point - thickness - 3, end_point - thickness - ( panel_horizontal ? 3 : 3));
cairo_stroke_preserve(c);
cairo_fill(c);
return;
}
if (count < thickness)
return;
while (((int) count) % 2) {
if (alt) {
start_point++;
alt = 0;
} else {
end_point--;
alt = 1;
}
count = end_point - start_point;
if (count < thickness)
return;
}
if (separator->style == 3 || separator->style == 4)
x_fix = round(thickness / 2) + (separator->style == 4 ? 1.0 : 0.0);
if (separator->style == 5 || separator->style == 6) {
x_fix = -1.0;
start_point = start_point + 2;
end_point--;
}
double separator_pattern[] = { len, len };
double separator_style6_pattern[] = { 1.0 };
cairo_set_source_rgba(c, separator->color.rgb[0], separator->color.rgb[1], separator->color.rgb[2], separator->color.alpha);
cairo_set_line_width(c, thickness);
if (separator->style == 6)
cairo_set_dash(c, separator_style6_pattern, 1, 0);
else
cairo_set_dash(c, separator_pattern, sizeof(separator_pattern) / sizeof(separator_pattern[0]), 0);
if (panel_horizontal) {
cairo_move_to(c, (separator->area.width / 2) - thickness + x_fix, start_point);
cairo_line_to(c, (separator->area.width / 2) - thickness + x_fix, end_point);
} else {
cairo_move_to(c, start_point, (separator->area.height / 2) - thickness + x_fix);
cairo_line_to(c, end_point, (separator->area.height / 2) - thickness + x_fix);
}
cairo_stroke(c);
}
// Tint2 : Separator
// Author: Oskari Rauta <oskari.rauta@gmail.com>
#ifndef SEPARATOR_H
#define SEPARATOR_H
#include "common.h"
#include "area.h"
typedef struct Separator {
Area area;
int style;
Color color;
double empty_thickness;
double thickness;
double len;
} Separator;
Separator *create_separator();
void destroy_separator(void *obj);
void init_separator();
void init_separator_panel(void *p);
void cleanup_separator();
gboolean resize_separator(void *obj);
void draw_separator(void *obj, cairo_t *c);
#endif
This diff is collapsed.
......@@ -119,6 +119,19 @@ extern GtkWidget *tooltip_task_show, *tooltip_show_after, *tooltip_hide_after;
extern GtkWidget *clock_format_tooltip, *clock_tmz_tooltip;
extern GtkWidget *tooltip_background;
// Separator
typedef struct Separator {
char name[256];
GtkWidget *container;
GtkWidget *page_separator;
GtkWidget *page_label;
GtkWidget *separator_background;
GtkWidget *separator_color;
GtkWidget *separator_style;
} Separator;
extern GArray *separators;
// Executor
typedef struct Executor {
char name[256];
......@@ -208,6 +221,11 @@ int background_index_safe(int index);
GtkWidget *create_properties();
void separator_create_new();
Separator *separator_get_last();
void separator_remove(int i);
void separator_update_indices();
void execp_create_new();
Executor *execp_get_last();
void execp_remove(int i);
......
......@@ -670,6 +670,26 @@ void config_write_battery(FILE *fp)
fprintf(fp, "\n");
}
void config_write_separator(FILE *fp)
{
for (int i = 0; i < separators->len; i++) {
fprintf(fp, "#-------------------------------------\n");
fprintf(fp, "# Separator %d\n", i + 1);
Separator *separator = &g_array_index(separators, Separator, i);
fprintf(fp, "separator = new\n");
GdkColor color;
gtk_color_button_get_color(GTK_COLOR_BUTTON(separator->separator_color), &color);
config_write_color(fp,
"separator_color",
color,
gtk_color_button_get_alpha(GTK_COLOR_BUTTON(separator->separator_color)) * 100 / 0xffff);
fprintf(fp, "separator_style = %d\n", (int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(separator->separator_style)));
fprintf(fp, "\n");
}
}
void config_write_execp(FILE *fp)
{
for (int i = 0; i < executors->len; i++) {
......@@ -789,6 +809,7 @@ void config_save_file(const char *path) {
config_write_launcher(fp);
config_write_clock(fp);
config_write_battery(fp);
config_write_separator(fp);
config_write_execp(fp);
config_write_tooltip(fp);
......@@ -1675,6 +1696,24 @@ void add_entry(char *key, char *value)
set_action(value, task_mouse_scroll_down);
}
/* Separator */
else if (strcmp(key, "separator") == 0) {
separator_create_new();
}
else if (strcmp(key, "separator_color") == 0) {
extract_values(value, &value1, &value2, &value3);
GdkColor col;
hex2gdk(value1, &col);
gtk_color_button_set_color(GTK_COLOR_BUTTON(separator_get_last()->separator_color), &col);
if (value2) {
int alpha = atoi(value2);
gtk_color_button_set_alpha(GTK_COLOR_BUTTON(separator_get_last()->separator_color), (alpha*65535)/100);
}
}
else if (strcmp(key, "separator_style") == 0) {
gtk_spin_button_set_value(GTK_SPIN_BUTTON(separator_get_last()->separator_style), atoi(value));
}
/* Executor */
else if (strcmp(key, "execp") == 0) {
execp_create_new();
......
......@@ -21,5 +21,6 @@ po
src/tint2conf/po
src/freespace
src/execplugin
src/separator
themes
doc
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment