]> Dogcows Code - chaz/tint2/commitdiff
*add* clock supports timezones
authorAndreas Fink <andreas.fink85@googlemail.com>
Wed, 30 Dec 2009 11:27:29 +0000 (11:27 +0000)
committerAndreas Fink <andreas.fink85@googlemail.com>
Wed, 30 Dec 2009 11:27:29 +0000 (11:27 +0000)
*add* first preparations for real transparency (tooltip works already, but panel does not. Therefore it is disabled in the source code)

src/clock/clock.c
src/clock/clock.h
src/config.c
src/panel.c
src/server.c
src/server.h
src/tint.c
src/tooltip/tooltip.c

index 876536cbca6407c147908210f1f075ed5ea67f15..115ba9fe1bf5a4794984f1db33e0863147249142 100644 (file)
@@ -24,6 +24,7 @@
 #include <pango/pangocairo.h>
 #include <unistd.h>
 #include <signal.h>
+#include <stdlib.h>
 
 #include "window.h"
 #include "server.h"
 
 
 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;
index 750a12e8af6e775fbe22c3c581f3931867ad0e62..d9d16fb29ad71f7a60c33d59301539181bbed076 100644 (file)
@@ -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;
index fe3f9fee2bce686cf2804bbac436378034ec2c53..cbb9d664e4dc1a0c5977a0d87a8b47647e30bfa5 100644 (file)
@@ -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);
index 6da20c53e04e79d021a8e03710af1917f384cd46..e2bbf9f69f1b1d1f13043af5b08028bd7743d074 100644 (file)
@@ -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
index 511eca5d49bbb51f2614a06ac225a2a0b8db7939..475c0b6272565a74e6e66c9357e3d4f868973f4f 100644 (file)
@@ -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);
+       }
+}
index aba113255c11c24b818124b036f4d65e7500c814..2769ff87dd516dc245ab93c63e12e9a30b556ace 100644 (file)
@@ -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();
index cdb72a88cfa70751b525e927e21895c6aec783a1..cd0b2b87df8e2c3183fd262955f704d3654c5041 100644 (file)
@@ -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);
index 7bfd7093f895ff710ad9d48713cbb95b7342ceb9..e63c1eb1ce9e3cfbd681dd197ad8f6ba971f0181 100644 (file)
@@ -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);
This page took 0.039726 seconds and 4 git commands to generate.