Commit 7393ceaf authored by lorthiois@bbsoft.fr's avatar lorthiois@bbsoft.fr

big change : panel_monitor = all will draw one panel per monitor, panel_size...

big change : panel_monitor = all will draw one panel per monitor, panel_size accept percentage or pixel, update documentation, taskbar_mode = single_monitor show tasks of current monitor

git-svn-id: http://tint2.googlecode.com/svn/trunk@32 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
parent 5b4d782c
2009-02-05
2009-02-07
- better multi-monitor capability :
-> panel_monitor = all : tint2 draw one panel per monitor
-> panel_size = 90% 30 : panel_size accept percentage or pixel
- change notation : MULTI_MONITOR changed to SINGLE_MONITOR
in SINGLE_MONITOR mode, tint2 draw one taskbar with tasks from current monitor
- removed sleep mode (replaced by panel_monitor = all)
- update documentation and sample config file
2009-02-03
- better fixed for Robert Escriva problem : set_panel_properties -> Reserved space
- fixed issue 13 with background detection
- fixed bug with disconnected monitor (in multi monitor mode)
......
No preview for this file type
No preview for this file type
......@@ -25,45 +25,55 @@
#include "window.h"
#include "server.h"
#include "taskbar.h"
#include "panel.h"
#include "area.h"
#include "clock.h"
#include "panel.h"
char *time1_format = 0;
char *time2_format = 0;
struct timeval time_clock;
int time_precision;
PangoFontDescription *time1_font_desc;
PangoFontDescription *time2_font_desc;
void init_clock(Clock *clock, int panel_height)
void init_clock(Clock *clock, Area *parent)
{
Panel *panel = (Panel *)parent;
char buf_time[40];
char buf_date[40];
int time_height, time_height_ink, date_height, date_height_ink;
clock->area.parent = parent;
clock->area.panel = panel;
clock->area.draw_foreground = draw_foreground_clock;
if (!time1_format) return;
if (strchr(time1_format, 'S') == NULL) time_precision = 60;
else time_precision = 1;
clock->area.posy = panel.area.pix.border.width + panel.area.paddingy;
clock->area.height = panel.area.height - (2 * clock->area.posy);
// update clock to force update (-time_precision)
struct timeval stv;
gettimeofday(&stv, 0);
time_clock.tv_sec = stv.tv_sec - time_precision;
time_clock.tv_sec -= time_clock.tv_sec % time_precision;
clock->area.posy = parent->pix.border.width + parent->paddingy;
clock->area.height = parent->height - (2 * clock->area.posy);
clock->area.width = 0; // force posx and width detection
clock->area.redraw = 1;
gettimeofday(&time_clock, 0);
time_clock.tv_sec -= time_clock.tv_sec % time_precision;
strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec));
if (time2_format)
strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec));
get_text_size(clock->time1_font_desc, &time_height_ink, &time_height, panel_height, buf_time, strlen(buf_time));
get_text_size(time1_font_desc, &time_height_ink, &time_height, parent->height, buf_time, strlen(buf_time));
clock->time1_posy = (clock->area.height - time_height) / 2;
if (time2_format) {
get_text_size(clock->time2_font_desc, &date_height_ink, &date_height, panel_height, buf_date, strlen(buf_date));
get_text_size(time2_font_desc, &date_height_ink, &date_height, parent->height, buf_date, strlen(buf_date));
clock->time1_posy -= ((date_height_ink + 2) / 2);
clock->time2_posy = clock->time1_posy + time_height + 2 - (time_height - time_height_ink)/2 - (date_height - date_height_ink)/2;
......@@ -73,6 +83,7 @@ void init_clock(Clock *clock, int panel_height)
void draw_foreground_clock (void *obj, cairo_t *c, int active)
{
Area *parent = ((Area*)obj)->parent;
Clock *clock = obj;
PangoLayout *layout;
char buf_time[40];
......@@ -89,12 +100,12 @@ redraw:
layout = pango_cairo_create_layout (c);
// check width
pango_layout_set_font_description (layout, clock->time1_font_desc);
pango_layout_set_font_description (layout, time1_font_desc);
pango_layout_set_indent(layout, 0);
pango_layout_set_text (layout, buf_time, strlen(buf_time));
pango_layout_get_pixel_size (layout, &time_width, NULL);
if (time2_format) {
pango_layout_set_font_description (layout, clock->time2_font_desc);
pango_layout_set_font_description (layout, time2_font_desc);
pango_layout_set_indent(layout, 0);
pango_layout_set_text (layout, buf_date, strlen(buf_date));
pango_layout_get_pixel_size (layout, &date_width, NULL);
......@@ -107,15 +118,15 @@ redraw:
//printf("clock_width %d, new_width %d\n", clock->area.width, new_width);
// resize clock
clock->area.width = new_width;
panel.clock.area.posx = panel.area.width - panel.clock.area.width - panel.area.paddingxlr - panel.area.pix.border.width;
clock->area.posx = parent->width - clock->area.width - parent->paddingxlr - parent->pix.border.width;
g_object_unref (layout);
resize_taskbar();
resize_taskbar(parent);
goto redraw;
}
// draw layout
pango_layout_set_font_description (layout, clock->time1_font_desc);
pango_layout_set_font_description (layout, time1_font_desc);
pango_layout_set_width (layout, clock->area.width * PANGO_SCALE);
pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
pango_layout_set_text (layout, buf_time, strlen(buf_time));
......@@ -127,7 +138,7 @@ redraw:
pango_cairo_show_layout (c, layout);
if (time2_format) {
pango_layout_set_font_description (layout, clock->time2_font_desc);
pango_layout_set_font_description (layout, time2_font_desc);
pango_layout_set_indent(layout, 0);
pango_layout_set_text (layout, buf_date, strlen(buf_date));
pango_layout_set_width (layout, clock->area.width * PANGO_SCALE);
......
......@@ -3,7 +3,7 @@
*
* Clock with fonctionnal data (timeval, precision) and drawing data (area, font, ...).
* Each panel use his own drawing data.
*
*
**************************************************************************/
#ifndef CLOCK_H
......@@ -19,20 +19,21 @@ typedef struct Clock {
Area area;
config_color font;
PangoFontDescription *time1_font_desc;
PangoFontDescription *time2_font_desc;
int time1_posy;
int time2_posy;
} Clock;
extern char *time1_format;
extern char *time2_format;
extern struct timeval time_clock;
extern int time_precision;
extern PangoFontDescription *time1_font_desc;
extern PangoFontDescription *time2_font_desc;
// initialize clock : y position, precision, ...
void init_clock(Clock *clock, int panel_height);
void init_clock(Clock *clock, Area *parent);
void draw_foreground_clock (void *obj, cairo_t *c, int active);
......
This diff is collapsed.
/**************************************************************************
* config :
* config :
* - parse config file in Panel struct.
*
* Check COPYING file for Copyright
......@@ -9,16 +9,12 @@
#ifndef CONFIG_H
#define CONFIG_H
// list of background
GSList *list_back;
void init_config();
void cleanup_config();
int config_read_file (const char *path);
int config_read ();
void config_taskbar();
void config_finish ();
void cleanup_taskbar();
void cleanup ();
void save_config ();
#endif
This diff is collapsed.
......@@ -21,42 +21,55 @@
#include "systraybar.h"
extern int signal_pending;
// --------------------------------------------------
// mouse events
extern int mouse_middle;
extern int mouse_right;
extern int mouse_scroll_up;
extern int mouse_scroll_down;
//panel mode
enum { SINGLE_DESKTOP=0, MULTI_DESKTOP, MULTI_MONITOR };
enum { SINGLE_DESKTOP=0, MULTI_DESKTOP, SINGLE_MONITOR };
extern int panel_mode;
//panel alignment
//panel position
enum { LEFT=0x01, RIGHT=0x02, CENTER=0X04, TOP=0X08, BOTTOM=0x10 };
extern int panel_position;
extern int panel_refresh;
extern Task *task_active;
extern Task *task_drag;
typedef struct {
// always start with area
Area area;
// --------------------------------------------------
// backward compatibility
int old_config_file;
int old_task_icon;
int old_panel_background;
int old_task_background;
char *old_task_font;
// --------------------------------------------------
// panel
int signal_pending;
int sleep_mode;
int refresh;
Window main_win;
Pixmap root_pmap;
// 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;
int position;
int marginleft, marginright, marginy;
// --------------------------------------------------
// taskbar point to the first taskbar in panel.area.list. number of tasbar == nb_desktop x nb_monitor.
// task annd taskbar parameter per panel
Area g_taskbar;
Global_task g_task;
// --------------------------------------------------
// taskbar point to the first taskbar in panel.area.list.
// number of tasbar == nb_desktop
Taskbar *taskbar;
int mode;
int nb_desktop;
int nb_monitor;
Task *task_active;
Task *task_drag;
int nb_desktop;
// --------------------------------------------------
// clock
......@@ -65,28 +78,23 @@ typedef struct {
// --------------------------------------------------
// systray
Systraybar systraybar;
// --------------------------------------------------
// mouse events
int mouse_middle;
int mouse_right;
int mouse_scroll_up;
int mouse_scroll_down;
} Panel;
Panel panel;
extern Panel *panel1;
extern int nb_panel;
void visual_refresh ();
void set_panel_properties (Window win);
void window_draw_panel ();
void init_panel();
void cleanup_panel();
void visual_refresh(Panel *p);
void set_panel_properties(Panel *p);
void visible_object();
// draw background panel
void set_panel_background();
void set_panel_background(Panel *p);
// detect server.root_pmap
void get_root_pixmap();
Panel *get_panel(Window win);
#endif
......@@ -20,9 +20,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "server.h"
#include "panel.h"
#include "task.h"
#include "window.h"
......@@ -135,6 +135,38 @@ void *server_get_property (Window win, Atom at, Atom type, int *num_results)
}
void get_root_pixmap()
{
Pixmap ret = None;
unsigned long *res;
int c = 2;
do {
res = server_get_property (server.root_win, server.atom._XROOTPMAP_ID, XA_PIXMAP, 0);
if (res) {
ret = *((Pixmap*)res);
XFree(res);
break;
}
} while (--c > 0);
server.root_pmap = ret;
if (server.root_pmap == None)
fprintf(stderr, "pixmap background detection failed\n");
else {
XGCValues gcv;
gcv.ts_x_origin = 0;
gcv.ts_y_origin = 0;
gcv.fill_style = FillTiled;
uint mask = GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle | GCTile;
gcv.tile = server.root_pmap;
XChangeGC(server.dsp, server.gc, mask, &gcv);
}
}
int compareMonitor(const void *monitor1, const void *monitor2)
{
Monitor *m1 = (Monitor*)monitor1;
......@@ -161,8 +193,10 @@ int compareMonitor(const void *monitor1, const void *monitor2)
}
void get_monitors()
void get_monitors_and_desktops()
{
int i;
if (server.monitor) free(server.monitor);
server.nb_monitor = 0;
server.monitor = 0;
......@@ -172,8 +206,9 @@ void get_monitors()
XineramaScreenInfo *info = XineramaQueryScreens(server.dsp, &nb_monitor);
if (info) {
int i = 0, nb=0, j;
int nb=0, j;
i = 0;
server.monitor = calloc(nb_monitor, sizeof(Monitor));
while (i < nb_monitor) {
for (j = 0; j < i; j++) {
......@@ -190,7 +225,6 @@ void get_monitors()
}
}
//fprintf(stderr, "monitor %d added\n", i);
server.monitor[nb].x = info[i].x_org;
server.monitor[nb].y = info[i].y_org;
server.monitor[nb].width = info[i].width;
......@@ -214,6 +248,18 @@ next:
server.monitor[0].width = DisplayWidth (server.dsp, server.screen);
server.monitor[0].height = DisplayHeight (server.dsp, server.screen);
}
// detect number of desktops
for (i=0 ; i < 15 ; i++) {
server.nb_desktop = server_get_number_of_desktop ();
if (server.nb_desktop > 0) break;
sleep(1);
}
if (server.nb_desktop == 0) {
server.nb_desktop = 1;
fprintf(stderr, "tint2 warning : cannot found number of desktop.\n");
}
fprintf(stderr, "nb monitor %d, nb desktop %d\n", server.nb_monitor, server.nb_desktop);
}
......@@ -70,6 +70,7 @@ typedef struct
{
Display *dsp;
Window root_win;
// current desktop
int desktop;
int screen;
int depth;
......@@ -79,8 +80,6 @@ typedef struct
Monitor *monitor;
int got_root_win;
Visual *visual;
int posx, posy;
Pixmap pmap;
// root background
Pixmap root_pmap;
GC gc;
......@@ -100,9 +99,11 @@ void server_refresh_main_pixmap ();
void server_catch_error (Display *d, XErrorEvent *ev);
void server_init_atoms ();
// detect monitors
// doesn't count monitor included into another one
void get_monitors();
// detect root background
void get_root_pixmap();
// detect monitors and desktops
void get_monitors_and_desktops();
#endif
......@@ -28,7 +28,6 @@
#include "systraybar.h"
#include "server.h"
#include "window.h"
#include "panel.h"
......@@ -37,44 +36,5 @@ int resize_systray (Systraybar *sysbar)
return 0;
}
/*
// initialise taskbar posx and width
void resize_taskbar()
{
int taskbar_width, modulo_width, taskbar_on_screen;
if (panel.mode == MULTI_DESKTOP) taskbar_on_screen = panel.nb_desktop;
else taskbar_on_screen = panel.nb_monitor;
taskbar_width = panel.area.width - (2 * panel.area.paddingx) - (2 * panel.area.pix.border.width);
if (panel.clock.time1_format)
taskbar_width -= (panel.clock.area.width + panel.area.paddingx);
taskbar_width = (taskbar_width - ((taskbar_on_screen-1) * panel.area.paddingx)) / taskbar_on_screen;
if (taskbar_on_screen > 1)
modulo_width = (taskbar_width - ((taskbar_on_screen-1) * panel.area.paddingx)) % taskbar_on_screen;
else
modulo_width = 0;
int i, nb, modulo=0, posx=0;
nb = panel.nb_desktop * panel.nb_monitor;
for (i=0 ; i < nb ; i++) {
if ((i % taskbar_on_screen) == 0) {
posx = panel.area.pix.border.width + panel.area.paddingx;
modulo = modulo_width;
}
else posx += taskbar_width + panel.area.paddingx;
panel.taskbar[i].area.posx = posx;
panel.taskbar[i].area.width = taskbar_width;
if (modulo) {
panel.taskbar[i].area.width++;
modulo--;
}
resize_tasks(&panel.taskbar[i]);
}
}
*/
This diff is collapsed.
......@@ -19,14 +19,15 @@ typedef struct {
int text;
int icon;
int icon_size1;
int centered;
int maximum_width;
int font_shadow;
// icon position
int icon_posy;
int icon_size1;
int maximum_width;
// starting position for text ~ task_padding + task_border + icon_size
double text_posx, text_posy;
int font_shadow;
PangoFontDescription *font_desc;
config_color font;
config_color font_active;
......@@ -40,16 +41,14 @@ typedef struct {
// TODO: group task with list of windows here
Window win;
int desktop;
long *icon_data;
int icon_width;
int icon_height;
char *title;
int all_desktop;
} Task;
Global_task g_task;
void add_task (Window win);
void remove_task (Task *tsk);
......@@ -59,5 +58,6 @@ void draw_foreground_task (void *obj, cairo_t *c, int active);
void get_icon (Task *tsk);
void get_title(Task *tsk);
#endif
......@@ -26,6 +26,7 @@
#include <glib.h>
#include <Imlib2.h>
#include "task.h"
#include "taskbar.h"
#include "server.h"
#include "window.h"
......@@ -33,19 +34,106 @@
void init_taskbar()
{
Panel *panel;
int i, j;
for (i=0 ; i < nb_panel ; i++) {
panel = &panel1[i];
// taskbar
panel->g_taskbar.posy = panel->area.pix.border.width + panel->area.paddingy;
panel->g_taskbar.height = panel->area.height - (2 * panel->g_taskbar.posy);
panel->g_taskbar.redraw = 1;
// task
panel->g_task.area.draw_foreground = draw_foreground_task;
panel->g_task.area.posy = panel->g_taskbar.posy + panel->g_taskbar.pix.border.width + panel->g_taskbar.paddingy;
panel->g_task.area.height = panel->area.height - (2 * panel->g_task.area.posy);
panel->g_task.area.use_active = 1;
panel->g_task.area.redraw = 1;
if (panel->g_task.area.pix.border.rounded > panel->g_task.area.height/2) {
panel->g_task.area.pix.border.rounded = panel->g_task.area.height/2;
panel->g_task.area.pix_active.border.rounded = panel->g_task.area.pix.border.rounded;
}
// compute vertical position : text and icon
int height_ink, height;
get_text_size(panel->g_task.font_desc, &height_ink, &height, panel->area.height, "TAjpg", 5);
if (!panel->g_task.maximum_width)
panel->g_task.maximum_width = server.monitor[panel->monitor].width;
// add task_icon_size
panel->g_task.text_posx = panel->g_task.area.paddingxlr + panel->g_task.area.pix.border.width;
panel->g_task.text_posy = (panel->g_task.area.height - height) / 2.0;
if (panel->g_task.icon) {
panel->g_task.icon_size1 = panel->g_task.area.height - (2 * panel->g_task.area.paddingy);
panel->g_task.text_posx += panel->g_task.icon_size1;
panel->g_task.icon_posy = (panel->g_task.area.height - panel->g_task.icon_size1) / 2;
}
//printf("monitor %d, task_maximum_width %d\n", panel->monitor, panel->g_task.maximum_width);
Taskbar *tskbar;
panel->nb_desktop = server.nb_desktop;
panel->taskbar = calloc(panel->nb_desktop, sizeof(Taskbar));
for (j=0 ; j < panel->nb_desktop ; j++) {
tskbar = &panel->taskbar[j];
memcpy(&tskbar->area, &panel->g_taskbar, sizeof(Area));
tskbar->desktop = j;
}
resize_taskbar(panel);
}
}
void cleanup_taskbar()
{
Panel *panel;
int i, j;
GSList *l0;
Task *tsk;
for (i=0 ; i < nb_panel ; i++) {
panel = &panel1[i];
if (!panel->taskbar) continue;
for (j=0 ; j < panel->nb_desktop ; j++) {
l0 = panel->taskbar[j].area.list;
while (l0) {
tsk = l0->data;
l0 = l0->next;
// careful : remove_task change l0->next
remove_task (tsk);
}
free_area (&panel->taskbar[j].area);
}
free(panel->taskbar);
panel->taskbar = 0;
}
}
Task *task_get_task (Window win)
{
Task *tsk;
GSList *l0;
int i, nb;
nb = panel.nb_desktop * panel.nb_monitor;
for (i=0 ; i < nb ; i++) {
for (l0 = panel.taskbar[i].area.list; l0 ; l0 = l0->next) {
tsk = l0->data;
if (win == tsk->win)
return tsk;
}
int i, j;
for (i=0 ; i < nb_panel ; i++) {
for (j=0 ; j < panel1[i].nb_desktop ; j++) {
for (l0 = panel1[i].taskbar[j].area.list; l0 ; l0 = l0->next) {
tsk = l0->data;
if (win == tsk->win)
return tsk;
}
}
}
return 0;
}
......@@ -54,7 +142,7 @@ Task *task_get_task (Window win)
void task_refresh_tasklist ()
{
Window *win, active_win;
int num_results, i, j, nb;
int num_results, i, j, k;
GSList *l0;
Task *tsk;
......@@ -64,29 +152,30 @@ void task_refresh_tasklist ()
// Remove any old and set active win
active_win = window_get_active ();
if (panel.task_active) {
panel.task_active->area.is_active = 0;
panel.task_active = 0;
if (task_active) {
task_active->area.is_active = 0;
task_active = 0;
}
nb = panel.nb_desktop * panel.nb_monitor;
for (i=0 ; i < nb ; i++) {
l0 = panel.taskbar[i].area.list;
while (l0) {
tsk = l0->data;
l0 = l0->next;
if (tsk->win == active_win) {
tsk->area.is_active = 1;
panel.task_active = tsk;
for (i=0 ; i < nb_panel ; i++) {
for (j=0 ; j < panel1[i].nb_desktop ; j++) {
l0 = panel1[i].taskbar[j].area.list;
while (l0) {
tsk = l0->data;
l0 = l0->next;
if (tsk->win == active_win) {
tsk->area.is_active = 1;
task_active = tsk;
}
for (k = 0; k < num_results; k++) {
if (tsk->win == win[k]) break;
}
// careful : remove_task change l0->next
if (tsk->win != win[k]) remove_task (tsk);
}
for (j = 0; j < num_results; j++) {
if (tsk->win == win[j]) break;
}
// careful : remove_task change l0->next
if (tsk->win != win[j]) remove_task (tsk);
}
}
}
// Add any new
......@@ -103,19 +192,23 @@ int resize_tasks (Taskbar *taskbar)
int ret, task_count, pixel_width, modulo_width=0;
int x, taskbar_width;
Task *tsk;
Panel *panel = (Panel*)taskbar->area.panel;
GSList *l;
// new task width for 'desktop'
task_count = g_slist_length(taskbar->area.list);
if (!task_count) pixel_width = g_task.maximum_width;
if (!task_count) pixel_width = panel->g_task.maximum_width;
else {
taskbar_width = taskbar->area.width - (2 * g_taskbar.pix.border.width) - (2 * g_taskbar.paddingxlr);
if (task_count>1) taskbar_width -= ((task_count-1) * g_taskbar.paddingx);
taskbar_width = taskbar->area.width - (2 * panel->g_taskbar.pix.border.width) - (2 * panel->g_taskbar.paddingxlr);
if (task_count>1) taskbar_width -= ((task_count-1) * panel->g_taskbar.paddingx);