char *time1_format=0;
char *time2_format=0;
+char *time_tooltip_format=0;
char *clock_lclick_command=0;
char *clock_rclick_command=0;
struct timeval time_clock;
PangoFontDescription *time2_font_desc=0;
static char buf_time[40];
static char buf_date[40];
+static char buf_tooltip[40];
int clock_enabled;
}
+const char* clock_get_tooltip(void* obj)
+{
+ return buf_tooltip;
+}
+
+
void init_clock()
{
if(time1_format) {
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;
}
+
+ 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));
+ }
}
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)
return 0;
}
+
+Taskbar *click_taskbar (Panel *panel, int x, int y)
+{
+ Taskbar *tskbar;
+ int i;
+
+ if (panel_horizontal) {
+ for (i=0; i < panel->nb_desktop ; i++) {
+ tskbar = &panel->taskbar[i];
+ if (tskbar->area.on_screen && x >= tskbar->area.posx && x <= (tskbar->area.posx + tskbar->area.width))
+ return tskbar;
+ }
+ }
+ else {
+ for (i=0; i < panel->nb_desktop ; i++) {
+ tskbar = &panel->taskbar[i];
+ if (tskbar->area.on_screen && y >= tskbar->area.posy && y <= (tskbar->area.posy + tskbar->area.height))
+ return tskbar;
+ }
+ }
+ return NULL;
+}
+
+
+Task *click_task (Panel *panel, int x, int y)
+{
+ GSList *l0;
+ Taskbar *tskbar;
+
+ if ( (tskbar = click_taskbar(panel, x, y)) ) {
+ if (panel_horizontal) {
+ Task *tsk;
+ for (l0 = tskbar->area.list; l0 ; l0 = l0->next) {
+ tsk = l0->data;
+ if (tsk->area.on_screen && x >= tsk->area.posx && x <= (tsk->area.posx + tsk->area.width)) {
+ return tsk;
+ }
+ }
+ }
+ else {
+ Task *tsk;
+ for (l0 = tskbar->area.list; l0 ; l0 = l0->next) {
+ tsk = l0->data;
+ if (tsk->area.on_screen && y >= tsk->area.posy && y <= (tsk->area.posy + tsk->area.height)) {
+ return tsk;
+ }
+ }
+ }
+ }
+ return NULL;
+}
+
+
+int click_padding(Panel *panel, int x, int y)
+{
+ if (panel_horizontal) {
+ if (x < panel->area.paddingxlr || x > panel->area.width-panel->area.paddingxlr)
+ return 1;
+ }
+ else {
+ if (y < panel->area.paddingxlr || y > panel->area.height-panel->area.paddingxlr)
+ return 1;
+ }
+ return 0;
+}
+
+
+int click_clock(Panel *panel, int x, int y)
+{
+ Clock clk = panel->clock;
+ if (panel_horizontal) {
+ if (clk.area.on_screen && x >= clk.area.posx && x <= (clk.area.posx + clk.area.width))
+ return TRUE;
+ } else {
+ if (clk.area.on_screen && y >= clk.area.posy && y <= (clk.area.posy + clk.area.height))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+Area* click_area(Panel *panel, int x, int y)
+{
+ Area* result = &panel->area;
+ Area* new_result = result;
+ do {
+ result = new_result;
+ GSList* it = result->list;
+ while (it) {
+ Area* a = it->data;
+ if (panel_horizontal) {
+ if (a->on_screen && x >= a->posx && x <= (a->posx + a->width)) {
+ new_result = a;
+ break;
+ }
+ } else {
+ if (a->on_screen && y >= a->posy && y <= (a->posy + a->height)) {
+ new_result = a;
+ break;
+ }
+ }
+ it = it->next;
+ }
+ } while (new_result != result);
+ return result;
+}
// detect witch panel
Panel *get_panel(Window win);
-#endif
+Taskbar *click_taskbar (Panel *panel, int x, int y);
+Task *click_task (Panel *panel, int x, int y);
+int click_padding(Panel *panel, int x, int y);
+int click_clock(Panel *panel, int x, int y);
+Area* click_area(Panel *panel, int x, int y);
+#endif
static int urgent_timer = 0;
+const char* task_get_tooltip(void* obj)
+{
+ Task* t = obj;
+ return t->title;
+}
+
+
Task *add_task (Window win)
{
if (!win) return 0;
new_tsk2->area.on_screen = 0;
}
new_tsk2->title = new_tsk.title;
+ new_tsk2->area._get_tooltip_text = task_get_tooltip;
new_tsk2->icon = new_tsk.icon;
new_tsk2->icon_active = new_tsk.icon_active;
new_tsk2->icon_width = new_tsk.icon_width;
Window win = tsk->win;
int desktop = tsk->desktop;
- if (g_tooltip.task == tsk) {
- tooltip_hide();
- alarm(0);
- g_tooltip.task = 0;
- }
-
// free title and icon just for the first task
// even with task_on_all_desktop and with task_on_all_panel
//printf("remove_task %s %d\n", tsk->title, tsk->desktop);
if (!panel->g_task.text && !g_tooltip.enabled) return;
- if (g_tooltip.task == tsk) {
- tooltip_hide();
- alarm(0);
- g_tooltip.task = 0;
- }
-
name = server_get_property (tsk->win, server.atom._NET_WM_VISIBLE_NAME, server.atom.UTF8_STRING, 0);
if (!name || !strlen(name)) {
name = server_get_property (tsk->win, server.atom._NET_WM_NAME, server.atom.UTF8_STRING, 0);
}
-Taskbar *click_taskbar (Panel *panel, int x, int y)
-{
- Taskbar *tskbar;
- int i;
-
- if (panel_horizontal) {
- for (i=0; i < panel->nb_desktop ; i++) {
- tskbar = &panel->taskbar[i];
- if (tskbar->area.on_screen && x >= tskbar->area.posx && x <= (tskbar->area.posx + tskbar->area.width))
- return tskbar;
- }
- }
- else {
- for (i=0; i < panel->nb_desktop ; i++) {
- tskbar = &panel->taskbar[i];
- if (tskbar->area.on_screen && y >= tskbar->area.posy && y <= (tskbar->area.posy + tskbar->area.height))
- return tskbar;
- }
- }
- return NULL;
-}
-
-
-Task *click_task (Panel *panel, int x, int y)
-{
- GSList *l0;
- Taskbar *tskbar;
-
- if ( (tskbar = click_taskbar(panel, x, y)) ) {
- if (panel_horizontal) {
- Task *tsk;
- for (l0 = tskbar->area.list; l0 ; l0 = l0->next) {
- tsk = l0->data;
- if (tsk->area.on_screen && x >= tsk->area.posx && x <= (tsk->area.posx + tsk->area.width)) {
- return tsk;
- }
- }
- }
- else {
- Task *tsk;
- for (l0 = tskbar->area.list; l0 ; l0 = l0->next) {
- tsk = l0->data;
- if (tsk->area.on_screen && y >= tsk->area.posy && y <= (tsk->area.posy + tsk->area.height)) {
- return tsk;
- }
- }
- }
- }
- return NULL;
-}
-
-
-int click_padding(Panel *panel, int x, int y)
-{
- if (panel_horizontal) {
- if (x < panel->area.paddingxlr || x > panel->area.width-panel->area.paddingxlr)
- return 1;
- }
- else {
- if (y < panel->area.paddingxlr || y > panel->area.height-panel->area.paddingxlr)
- return 1;
- }
- return 0;
-}
-
-
-int click_clock(Panel *panel, int x, int y)
-{
- Clock clk = panel->clock;
- if (panel_horizontal) {
- if (clk.area.on_screen && x >= clk.area.posx && x <= (clk.area.posx + clk.area.width))
- return TRUE;
- } else {
- if (clk.area.on_screen && y >= clk.area.posy && y <= (clk.area.posy + clk.area.height))
- return TRUE;
- }
- return FALSE;
-}
-
-
void window_action (Task *tsk, int action)
{
if (!tsk) return;
case MotionNotify: {
if (!g_tooltip.enabled) break;
Panel* panel = get_panel(e.xmotion.window);
- Task* task = click_task(panel, e.xmotion.x, e.xmotion.y);
- if (task)
- tooltip_trigger_show(task, e.xmotion.x_root, e.xmotion.y_root);
+ Area* area = click_area(panel, e.xmotion.x, e.xmotion.y);
+ if (area->_get_tooltip_text) {
+ tooltip_trigger_show(area, panel, e.xmotion.x_root, e.xmotion.y_root);
+ }
else
tooltip_trigger_hide();
break;
tooltip_update();
break;
-
case PropertyNotify:
event_property_notify(&e);
break;
// give the tooltip some reasonable default values
Tooltip g_tooltip = {
- .task = 0,
+ .area = 0,
+ .panel = 0,
.window = 0,
.show_timeout = { 0, 0 },
.hide_timeout = { 0, 0 },
stop_timeouts();
tooltip_hide();
g_tooltip.enabled = False;
- if (g_tooltip.task) {
- g_tooltip.task = 0;
- }
+ g_tooltip.area = 0;
if (g_tooltip.window) {
XDestroyWindow(server.dsp, g_tooltip.window);
g_tooltip.window = 0;
}
-void tooltip_trigger_show(Task* task, int x_root, int y_root)
+void tooltip_trigger_show(Area* area, Panel* p, int x_root, int y_root)
{
x = x_root;
y = y_root;
-
- if (g_tooltip.mapped && g_tooltip.task != task) {
- g_tooltip.task = task;
+ g_tooltip.panel = p;
+ if (g_tooltip.mapped && g_tooltip.area != area) {
+ g_tooltip.area = area;
tooltip_update();
stop_timeouts();
}
else if (!g_tooltip.mapped) {
- g_tooltip.task = task;
start_show_timeout();
}
}
void tooltip_show()
{
+ Area* area = click_area(g_tooltip.panel, x, y);
stop_timeouts();
- if (!g_tooltip.mapped) {
+ if (!g_tooltip.mapped && area->_get_tooltip_text) {
+ g_tooltip.area = area;
g_tooltip.mapped = True;
XMapWindow(server.dsp, g_tooltip.window);
XFlush(server.dsp);
c = cairo_create(cs);
layout = pango_cairo_create_layout(c);
pango_layout_set_font_description(layout, g_tooltip.font_desc);
- pango_layout_set_text(layout, g_tooltip.task->title, -1);
+ pango_layout_set_text(layout, g_tooltip.area->_get_tooltip_text(g_tooltip.area), -1);
PangoRectangle r1, r2;
pango_layout_get_pixel_extents(layout, &r1, &r2);
width = 2*g_tooltip.border.width + 2*g_tooltip.paddingx + r2.width;
height = 2*g_tooltip.border.width + 2*g_tooltip.paddingy + r2.height;
- Panel* panel = g_tooltip.task->area.panel;
+ Panel* panel = g_tooltip.panel;
if (panel_horizontal && panel_position & BOTTOM)
y = panel->posy-height;
else if (panel_horizontal && panel_position & TOP)
// it seems quite impossible that the height needs to be adjusted, but we do it anyway.
int min_x, min_y, max_width, max_height;
- Panel* panel = g_tooltip.task->area.panel;
+ Panel* panel = g_tooltip.panel;
int screen_width = server.monitor[panel->monitor].x + server.monitor[panel->monitor].width;
int screen_height = server.monitor[panel->monitor].y + server.monitor[panel->monitor].height;
if ( x+width <= screen_width && y+height <= screen_height && x>=0 && y>=0)
void tooltip_update()
{
- if (!g_tooltip.task) {
+ if (!g_tooltip.area->_get_tooltip_text) {
tooltip_hide();
return;
}
cairo_set_source_rgba(c, fc.color[0], fc.color[1], fc.color[2], fc.alpha);
layout = pango_cairo_create_layout(c);
pango_layout_set_font_description(layout, g_tooltip.font_desc);
- pango_layout_set_text(layout, g_tooltip.task->title, -1);
+ pango_layout_set_text(layout, g_tooltip.area->_get_tooltip_text(g_tooltip.area), -1);
PangoRectangle r1, r2;
pango_layout_get_pixel_extents(layout, &r1, &r2);
pango_layout_set_width(layout, width*PANGO_SCALE);
void tooltip_trigger_hide(Tooltip* tooltip)
{
if (g_tooltip.mapped) {
- g_tooltip.task = 0;
+ g_tooltip.area = 0;
start_hide_timeout();
}
else {
#include <sys/time.h>
#include "task.h"
+#include "panel.h"
typedef struct {
- Task* task;
+ Area* area;
+ Panel* panel;
Window window;
struct timespec show_timeout;
struct timespec hide_timeout;
void init_tooltip();
void cleanup_tooltip();
-void tooltip_trigger_show(Task* task, int x, int y);
+void tooltip_trigger_show(Area* area, Panel* p, int x, int y);
void tooltip_show();
void tooltip_update();
void tooltip_trigger_hide();
void (*_resize)(void *obj);
void (*_add_child)(void *obj);
int (*_remove_child)(void *obj);
+ const char* (*_get_tooltip_text)(void *obj);
} Area;
// draw rounded rectangle
void draw_rect(cairo_t *c, double x, double y, double w, double h, double r);
-
#endif