*add* first preparations for real transparency (tooltip works already, but panel does not. Therefore it is disabled in the source code)
#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;
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;
}
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));
}
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);
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));
}
}
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;
}
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;
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;
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);
}
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);
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
* 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>
void cleanup_server()
{
if (name_trayer) free(name_trayer);
+ XFreeColormap(server.dsp, server.colormap);
}
}
+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);
+ }
+}
// root background
Pixmap root_pmap;
GC gc;
+ Colormap colormap;
Global_atom atom;
} Server_global;
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();
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);
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);
}
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);