*add* clock supports timezones
*add* first preparations for real transparency (tooltip works already, but panel does not. Therefore it is disabled in the source code) git-svn-id: http://tint2.googlecode.com/svn/trunk@304 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
parent
527c91f005
commit
c65ad3628d
8 changed files with 98 additions and 26 deletions
|
@ -24,6 +24,7 @@
|
|||
#include <pango/pangocairo.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "window.h"
|
||||
#include "server.h"
|
||||
|
@ -35,8 +36,11 @@
|
|||
|
||||
|
||||
char *time1_format=0;
|
||||
char *time1_timezone=0;
|
||||
char *time2_format=0;
|
||||
char *time2_timezone=0;
|
||||
char *time_tooltip_format=0;
|
||||
char *time_tooltip_timezone=0;
|
||||
char *clock_lclick_command=0;
|
||||
char *clock_rclick_command=0;
|
||||
struct timeval time_clock;
|
||||
|
@ -60,10 +64,21 @@ void update_clocks()
|
|||
panel_refresh = 1;
|
||||
}
|
||||
|
||||
struct tm* clock_gettime_for_tz(const char* timezone) {
|
||||
if (timezone) {
|
||||
const char* old_tz = getenv("TZ");
|
||||
setenv("TZ", timezone, 1);
|
||||
struct tm* result = localtime(&time_clock.tv_sec);
|
||||
if (old_tz) setenv("TZ", old_tz, 1);
|
||||
else unsetenv("TZ");
|
||||
return result;
|
||||
}
|
||||
else return localtime(&time_clock.tv_sec);
|
||||
}
|
||||
|
||||
const char* clock_get_tooltip(void* obj)
|
||||
{
|
||||
strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, localtime(&time_clock.tv_sec));
|
||||
strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, clock_gettime_for_tz(time_tooltip_timezone));
|
||||
return buf_tooltip;
|
||||
}
|
||||
|
||||
|
@ -93,10 +108,10 @@ void init_clock_panel(void *p)
|
|||
clock->area.redraw = 1;
|
||||
clock->area.on_screen = 1;
|
||||
|
||||
strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec));
|
||||
strftime(buf_time, sizeof(buf_time), time1_format, clock_gettime_for_tz(time1_timezone));
|
||||
get_text_size(time1_font_desc, &time_height_ink, &time_height, panel->area.height, buf_time, strlen(buf_time));
|
||||
if (time2_format) {
|
||||
strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec));
|
||||
strftime(buf_date, sizeof(buf_date), time2_format, clock_gettime_for_tz(time2_timezone));
|
||||
get_text_size(time2_font_desc, &date_height_ink, &date_height, panel->area.height, buf_date, strlen(buf_date));
|
||||
}
|
||||
|
||||
|
@ -115,7 +130,7 @@ void init_clock_panel(void *p)
|
|||
|
||||
clock->time1_posy = (clock->area.height - time_height) / 2;
|
||||
if (time2_format) {
|
||||
strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec));
|
||||
strftime(buf_date, sizeof(buf_date), time2_format, clock_gettime_for_tz(time2_timezone));
|
||||
get_text_size(time2_font_desc, &date_height_ink, &date_height, panel->area.height, buf_date, strlen(buf_date));
|
||||
|
||||
clock->time1_posy -= ((date_height_ink + 2) / 2);
|
||||
|
@ -124,7 +139,7 @@ void init_clock_panel(void *p)
|
|||
|
||||
if (time_tooltip_format) {
|
||||
clock->area._get_tooltip_text = clock_get_tooltip;
|
||||
strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, localtime(&time_clock.tv_sec));
|
||||
strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, clock_gettime_for_tz(time_tooltip_timezone));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,18 +151,17 @@ void cleanup_clock()
|
|||
pango_font_description_free(time1_font_desc);
|
||||
if (time2_font_desc)
|
||||
pango_font_description_free(time2_font_desc);
|
||||
if (time1_format)
|
||||
g_free(time1_format);
|
||||
if (time2_format)
|
||||
g_free(time2_format);
|
||||
if (time_tooltip_format)
|
||||
g_free(time_tooltip_format);
|
||||
if (clock_lclick_command)
|
||||
g_free(clock_lclick_command);
|
||||
if (clock_rclick_command)
|
||||
g_free(clock_rclick_command);
|
||||
g_free(time1_format);
|
||||
g_free(time2_format);
|
||||
g_free(time_tooltip_format);
|
||||
g_free(time1_timezone);
|
||||
g_free(time2_timezone);
|
||||
g_free(time_tooltip_timezone);
|
||||
g_free(clock_lclick_command);
|
||||
g_free(clock_rclick_command);
|
||||
time1_font_desc = time2_font_desc = 0;
|
||||
time1_format = time2_format = 0;
|
||||
time1_format = time2_format = time_tooltip_format = 0;
|
||||
time1_timezone = time2_timezone = time_tooltip_timezone = 0;
|
||||
clock_lclick_command = clock_rclick_command = 0;
|
||||
}
|
||||
|
||||
|
@ -194,9 +208,9 @@ void resize_clock (void *obj)
|
|||
|
||||
clock->area.redraw = 1;
|
||||
time_width = date_width = 0;
|
||||
strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec));
|
||||
strftime(buf_time, sizeof(buf_time), time1_format, clock_gettime_for_tz(time1_timezone));
|
||||
if (time2_format)
|
||||
strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec));
|
||||
strftime(buf_date, sizeof(buf_date), time2_format, clock_gettime_for_tz(time2_timezone));
|
||||
|
||||
// vertical panel doen't adjust width
|
||||
if (!panel_horizontal) return;
|
||||
|
|
|
@ -25,8 +25,11 @@ typedef struct Clock {
|
|||
|
||||
|
||||
extern char *time1_format;
|
||||
extern char *time1_timezone;
|
||||
extern char *time2_format;
|
||||
extern char *time2_timezone;
|
||||
extern char *time_tooltip_format;
|
||||
extern char *time_tooltip_timezone;
|
||||
extern PangoFontDescription *time1_font_desc;
|
||||
extern PangoFontDescription *time2_font_desc;
|
||||
extern char *clock_lclick_command;
|
||||
|
|
12
src/config.c
12
src/config.c
|
@ -366,6 +366,14 @@ void add_entry (char *key, char *value)
|
|||
else if (strcmp (key, "time1_font") == 0) {
|
||||
time1_font_desc = pango_font_description_from_string (value);
|
||||
}
|
||||
else if (strcmp(key, "time1_timezone") == 0) {
|
||||
if (strlen(value) > 0)
|
||||
time1_timezone = strdup(value);
|
||||
}
|
||||
else if (strcmp(key, "time2_timezone") == 0) {
|
||||
if (strlen(value) > 0)
|
||||
time2_timezone = strdup(value);
|
||||
}
|
||||
else if (strcmp (key, "time2_font") == 0) {
|
||||
time2_font_desc = pango_font_description_from_string (value);
|
||||
}
|
||||
|
@ -391,6 +399,10 @@ void add_entry (char *key, char *value)
|
|||
if (strlen(value) > 0)
|
||||
time_tooltip_format = strdup (value);
|
||||
}
|
||||
else if (strcmp(key, "clock_tooltip_timezone") == 0) {
|
||||
if (strlen(value) > 0)
|
||||
time_tooltip_timezone = strdup(value);
|
||||
}
|
||||
else if (strcmp(key, "clock_lclick_command") == 0) {
|
||||
if (strlen(value) > 0)
|
||||
clock_lclick_command = strdup(value);
|
||||
|
|
|
@ -151,8 +151,9 @@ void init_panel()
|
|||
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 };
|
||||
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);
|
||||
XSetWindowAttributes att = { .event_mask=event_mask, .colormap=server.colormap, .background_pixel=0, .border_pixel=0 };
|
||||
unsigned long mask = CWEventMask|CWColormap|CWBackPixel|CWBorderPixel;
|
||||
p->main_win = XCreateWindow(server.dsp, server.root_win, p->posx, p->posy, p->area.width, p->area.height, 0, server.depth, InputOutput, server.visual, mask, &att);
|
||||
}
|
||||
else {
|
||||
// old panel
|
||||
|
|
38
src/server.c
38
src/server.c
|
@ -18,6 +18,8 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**************************************************************************/
|
||||
|
||||
#include <X11/extensions/Xrender.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
@ -94,6 +96,7 @@ void server_init_atoms ()
|
|||
void cleanup_server()
|
||||
{
|
||||
if (name_trayer) free(name_trayer);
|
||||
XFreeColormap(server.dsp, server.colormap);
|
||||
}
|
||||
|
||||
|
||||
|
@ -299,3 +302,38 @@ void get_desktops()
|
|||
}
|
||||
|
||||
|
||||
void server_init_visual()
|
||||
{
|
||||
int real_transparency = 0;
|
||||
XVisualInfo *xvi;
|
||||
XVisualInfo templ = { .screen=server.screen, .depth=32, .class=TrueColor };
|
||||
int nvi;
|
||||
xvi = XGetVisualInfo(server.dsp, VisualScreenMask|VisualDepthMask|VisualClassMask, &templ, &nvi);
|
||||
|
||||
Visual *visual = 0;
|
||||
if (xvi) {
|
||||
int i;
|
||||
XRenderPictFormat *format;
|
||||
for (i = 0; i < nvi; i++) {
|
||||
format = XRenderFindVisualFormat(server.dsp, xvi[i].visual);
|
||||
if (format->type == PictTypeDirect && format->direct.alphaMask) {
|
||||
visual = xvi[i].visual;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
XFree (xvi);
|
||||
|
||||
if (visual && real_transparency) {
|
||||
printf("real transparency on... depth: %d\n", server.depth);
|
||||
server.depth = 32;
|
||||
server.colormap = XCreateColormap(server.dsp, server.root_win, visual, AllocNone);
|
||||
server.visual = visual;
|
||||
}
|
||||
else {
|
||||
server.depth = DefaultDepth(server.dsp, server.screen);
|
||||
printf("real transparency off.... depth: %d\n", server.depth);
|
||||
server.colormap = DefaultColormap(server.dsp, server.screen);
|
||||
server.visual = DefaultVisual(server.dsp, server.screen);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@ typedef struct
|
|||
// root background
|
||||
Pixmap root_pmap;
|
||||
GC gc;
|
||||
Colormap colormap;
|
||||
Global_atom atom;
|
||||
} Server_global;
|
||||
|
||||
|
@ -110,6 +111,7 @@ void server_refresh_root_pixmap ();
|
|||
void server_refresh_main_pixmap ();
|
||||
void server_catch_error (Display *d, XErrorEvent *ev);
|
||||
void server_init_atoms ();
|
||||
void server_init_visual();
|
||||
|
||||
// detect root background
|
||||
void get_root_pixmap();
|
||||
|
|
|
@ -101,17 +101,15 @@ void init (int argc, char *argv[])
|
|||
server_init_atoms ();
|
||||
server.screen = DefaultScreen (server.dsp);
|
||||
server.root_win = RootWindow(server.dsp, server.screen);
|
||||
server.depth = DefaultDepth (server.dsp, server.screen);
|
||||
server.visual = DefaultVisual (server.dsp, server.screen);
|
||||
server.desktop = server_get_current_desktop ();
|
||||
XGCValues gcv;
|
||||
server.gc = XCreateGC (server.dsp, server.root_win, (unsigned long)0, &gcv);
|
||||
|
||||
server_init_visual();
|
||||
XSetErrorHandler ((XErrorHandler) server_catch_error);
|
||||
|
||||
imlib_context_set_display (server.dsp);
|
||||
imlib_context_set_visual (server.visual);
|
||||
imlib_context_set_colormap (DefaultColormap (server.dsp, server.screen));
|
||||
imlib_context_set_colormap (server.colormap);
|
||||
|
||||
/* Catch events */
|
||||
XSelectInput (server.dsp, server.root_win, PropertyChangeMask|StructureNotifyMask);
|
||||
|
|
|
@ -62,8 +62,12 @@ void init_tooltip()
|
|||
XSetWindowAttributes attr;
|
||||
attr.override_redirect = True;
|
||||
attr.event_mask = StructureNotifyMask;
|
||||
attr.colormap = server.colormap;
|
||||
attr.background_pixel = 0;
|
||||
attr.border_pixel = 0;
|
||||
unsigned long mask = CWEventMask|CWColormap|CWBorderPixel|CWBackPixel|CWOverrideRedirect;
|
||||
if (g_tooltip.window) XDestroyWindow(server.dsp, g_tooltip.window);
|
||||
g_tooltip.window = XCreateWindow(server.dsp, server.root_win, 0, 0, 100, 20, 0, server.depth, InputOutput, CopyFromParent, CWOverrideRedirect|CWEventMask, &attr);
|
||||
g_tooltip.window = XCreateWindow(server.dsp, server.root_win, 0, 0, 100, 20, 0, server.depth, InputOutput, server.visual, mask, &attr);
|
||||
}
|
||||
|
||||
|
||||
|
@ -212,7 +216,7 @@ void tooltip_update()
|
|||
c = cairo_create(cs);
|
||||
Color bc = g_tooltip.background_color;
|
||||
cairo_rectangle(c, 0, 0, width, height);
|
||||
cairo_set_source_rgb(c, bc.color[0], bc.color[1], bc.color[2]);
|
||||
cairo_set_source_rgba(c, bc.color[0], bc.color[1], bc.color[2], bc.alpha);
|
||||
cairo_fill(c);
|
||||
Border b = g_tooltip.border;
|
||||
cairo_set_source_rgba(c, b.color[0], b.color[1], b.color[2], b.alpha);
|
||||
|
|
Loading…
Reference in a new issue