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
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user