forked from sargon/trayer-srg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixedtip.c
158 lines (130 loc) · 4.06 KB
/
fixedtip.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* Metacity fixed tooltip routine */
/*
* Copyright (C) 2001 Havoc Pennington
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#include "fixedtip.h"
static GtkWidget *tip = NULL;
static GtkWidget *label = NULL;
static int screen_width = 0;
static int screen_height = 0;
static gboolean
button_press_handler (GtkWidget *tip,
GdkEvent *event,
void *data)
{
fixed_tip_hide ();
return FALSE;
}
static gboolean
expose_handler (GtkTooltips *tooltips)
{
gtk_paint_flat_box (tip->style, tip->window,
GTK_STATE_NORMAL, GTK_SHADOW_OUT,
NULL, tip, "tooltip",
0, 0, -1, -1);
return FALSE;
}
void
fixed_tip_show (int screen_number,
int root_x, int root_y,
gboolean strut_is_vertical,
int strut,
const char *markup_text)
{
int w, h;
if (tip == NULL)
{
tip = gtk_window_new (GTK_WINDOW_POPUP);
#ifdef HAVE_GTK_MULTIHEAD
{
GdkScreen *gdk_screen;
gdk_screen = gdk_display_get_screen (gdk_get_default_display (),
screen_number);
gtk_window_set_screen (GTK_WINDOW (tip),
gdk_screen);
screen_width = gdk_screen_get_width (gdk_screen);
screen_height = gdk_screen_get_height (gdk_screen);
}
#else
screen_width = gdk_screen_width ();
screen_height = gdk_screen_height ();
#endif
gtk_widget_set_app_paintable (tip, TRUE);
//gtk_window_set_policy (GTK_WINDOW (tip), FALSE, FALSE, TRUE);
gtk_window_set_resizable(GTK_WINDOW (tip), FALSE);
gtk_widget_set_name (tip, "gtk-tooltips");
gtk_container_set_border_width (GTK_CONTAINER (tip), 4);
g_signal_connect (G_OBJECT (tip),
"expose_event",
G_CALLBACK (expose_handler),
NULL);
gtk_widget_add_events (tip, GDK_BUTTON_PRESS_MASK);
g_signal_connect (G_OBJECT (tip),
"button_press_event",
G_CALLBACK (button_press_handler),
NULL);
label = gtk_label_new (NULL);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
gtk_widget_show (label);
gtk_container_add (GTK_CONTAINER (tip), label);
g_signal_connect (G_OBJECT (tip),
"destroy",
G_CALLBACK (gtk_widget_destroyed),
&tip);
}
gtk_label_set_markup (GTK_LABEL (label), markup_text);
/* FIXME should also handle Xinerama here, just to be
* really cool
*/
gtk_window_get_size (GTK_WINDOW (tip), &w, &h);
/* pad between panel and message window */
#define PAD 5
if (strut_is_vertical)
{
if (strut > root_x)
root_x = strut + PAD;
else
root_x = strut - w - PAD;
root_y -= h / 2;
}
else
{
if (strut > root_y)
root_y = strut + PAD;
else
root_y = strut - h - PAD;
root_x -= w / 2;
}
/* Push onscreen */
if ((root_x + w) > screen_width)
root_x -= (root_x + w) - screen_width;
if ((root_y + h) > screen_height)
root_y -= (root_y + h) - screen_height;
gtk_window_move (GTK_WINDOW (tip), root_x, root_y);
gtk_widget_show (tip);
}
void
fixed_tip_hide (void)
{
if (tip)
{
gtk_widget_destroy (tip);
tip = NULL;
}
}