else if (strcmp (key, "tooltip_show_timeout") == 0) {
double timeout = atof(value);
int sec = (int)timeout;
- int usec = (timeout-sec)*1e6;
- g_tooltip.show_timeout.it_value = (struct timeval){.tv_sec=sec, .tv_usec=usec};
+ int nsec = (timeout-sec)*1e9;
+ if (nsec < 0) // can happen because of double is not precise such that (sec > timeout)==TRUE
+ nsec = 0;
+ g_tooltip.show_timeout = (struct timespec){.tv_sec=sec, .tv_nsec=nsec};
}
else if (strcmp (key, "tooltip_hide_timeout") == 0) {
double timeout = atof(value);
int sec = (int)timeout;
- int usec = (timeout-sec)*1e6;
- g_tooltip.hide_timeout.it_value = (struct timeval){.tv_sec=sec, .tv_usec=usec};
+ int nsec = (timeout-sec)*1e9;
+ if (nsec < 0) // can happen because of double is not precise such that (sec > timeout)==TRUE
+ nsec = 0;
+ g_tooltip.hide_timeout = (struct timespec){.tv_sec=sec, .tv_nsec=nsec};
}
else if (strcmp (key, "tooltip_padding") == 0) {
extract_values(value, &value1, &value2, &value3);
#include "server.h"
#include "tooltip.h"
#include "panel.h"
-
-// TODO: Use timer_create instead of setitimer, because SIGALRM is not the right signal for this...
-// Reason: If we want to implement autohide we have to use another signal...
+#include "timer.h"
static int x, y, width, height;
+// the next functions are helper functions for tooltip handling
+void start_show_timeout();
+void start_hide_timeout();
+void stop_timeouts();
+
// give the tooltip some reasonable default values
Tooltip g_tooltip = {
.task = 0,
.window = 0,
- .show_timeout = { .it_interval={0, 0}, .it_value={0, 0} },
- .hide_timeout = { .it_interval={0, 0}, .it_value={0, 0} },
+ .show_timeout = { 0, 0 },
+ .hide_timeout = { 0, 0 },
.enabled = False,
- .current_state = TOOLTIP_ABOUT_TO_HIDE,
.mapped = False,
.paddingx = 0,
.paddingy = 0,
.font_color = { .color={1, 1, 1}, .alpha=1 },
.background_color = { .color={0.5, 0.4, 0.5}, .alpha=1 },
.border = { .color={0, 0, 0}, .alpha=1, .width=1, .rounded=0 },
- .font_desc = 0
+ .font_desc = 0,
+ .show_timer_id = 0,
+ .hide_timer_id = 0
};
void init_tooltip()
if (!g_tooltip.font_desc)
g_tooltip.font_desc = pango_font_description_from_string("sans 10");
+ if (g_tooltip.show_timer_id == 0)
+ g_tooltip.show_timer_id = install_timer(0, 0, 0, 0, tooltip_show);
+ if (g_tooltip.hide_timer_id == 0)
+ g_tooltip.hide_timer_id = install_timer(0, 0, 0, 0, tooltip_hide);
+
XSetWindowAttributes attr;
attr.override_redirect = True;
attr.event_mask = ExposureMask;
void cleanup_tooltip()
{
- alarm(0);
+ stop_timeouts();
tooltip_hide();
g_tooltip.enabled = False;
- g_tooltip.current_state = TOOLTIP_ABOUT_TO_HIDE;
if (g_tooltip.task) {
g_tooltip.task = 0;
}
}
-void tooltip_sighandler(int sig)
-{
- if (g_tooltip.current_state == TOOLTIP_ABOUT_TO_SHOW)
- tooltip_show();
- else if (g_tooltip.current_state == TOOLTIP_ABOUT_TO_HIDE)
- tooltip_hide();
-}
-
-
void tooltip_trigger_show(Task* task, int x_root, int y_root)
{
x = x_root;
if (g_tooltip.mapped && g_tooltip.task != task) {
g_tooltip.task = task;
tooltip_update();
- alarm(0);
+ stop_timeouts();
}
else if (!g_tooltip.mapped) {
- g_tooltip.current_state = TOOLTIP_ABOUT_TO_SHOW;
g_tooltip.task = task;
- struct timeval t = g_tooltip.show_timeout.it_value;
- if (t.tv_sec == 0 && t.tv_usec == 0) {
- alarm(0);
- tooltip_show();
- }
- else
- setitimer(ITIMER_REAL, &g_tooltip.show_timeout, 0);
+ start_show_timeout();
}
}
g_tooltip.mapped = True;
XMapWindow(server.dsp, g_tooltip.window);
//tooltip_update();
- alarm(0);
}
}
void tooltip_trigger_hide(Tooltip* tooltip)
{
if (g_tooltip.mapped) {
- g_tooltip.current_state = TOOLTIP_ABOUT_TO_HIDE;
- struct timeval t = g_tooltip.hide_timeout.it_value;
g_tooltip.task = 0;
- if (t.tv_sec == 0 && t.tv_usec == 0) {
- tooltip_hide();
- alarm(0);
- }
- else
- setitimer(ITIMER_REAL, &g_tooltip.hide_timeout, 0);
+ start_hide_timeout();
}
else {
- // tooltip not visible yet, but maybe an alarm is still pending
- alarm(0);
+ // tooltip not visible yet, but maybe a timeout is still pending
+ stop_timeouts();
}
}
XUnmapWindow(server.dsp, g_tooltip.window);
}
}
+
+
+void start_show_timeout()
+{
+ reset_timer(g_tooltip.hide_timer_id, 0, 0, 0, 0);
+ struct timespec t = g_tooltip.show_timeout;
+ if (t.tv_sec == 0 && t.tv_nsec == 0)
+ tooltip_show();
+ else
+ reset_timer(g_tooltip.show_timer_id, t.tv_sec, t.tv_nsec, 0, 0);
+}
+
+
+void start_hide_timeout()
+{
+ reset_timer(g_tooltip.show_timer_id, 0, 0, 0, 0);
+ struct timespec t = g_tooltip.hide_timeout;
+ if (t.tv_sec == 0 && t.tv_nsec == 0)
+ tooltip_hide();
+ else
+ reset_timer(g_tooltip.hide_timer_id, t.tv_sec, t.tv_nsec, 0, 0);
+}
+
+void stop_timeouts()
+{
+ reset_timer(g_tooltip.show_timer_id, 0, 0, 0, 0);
+ reset_timer(g_tooltip.hide_timer_id, 0, 0, 0, 0);
+}