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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/**
* This file is a part of the Cairo-Dock project
*
* Copyright : (C) see the 'copyright' file.
* E-mail : see the 'copyright' file.
*
* 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 3
* 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, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <unistd.h>
#define __USE_XOPEN_EXTENDED
#include <stdlib.h>
#include <sys/stat.h>
#define __USE_POSIX
#include <time.h>
#include <glib/gstdio.h>
#include <glib/gi18n.h>
#include <gdk/gdkx.h>
#include "config.h"
#include "cairo-dock-config.h"
#include "cairo-dock-keyfile-utilities.h"
#include "cairo-dock-module-manager.h"
#include "cairo-dock-module-factory.h"
#include "cairo-dock-dock-manager.h"
#include "cairo-dock-gui-manager.h"
#include "cairo-dock-gui-factory.h"
#include "cairo-dock-task.h"
#include "cairo-dock-log.h"
#include "cairo-dock-packages.h"
#include "cairo-dock-keybinder.h"
#include "cairo-dock-X-manager.h"
#include "cairo-dock-X-utilities.h"
#include "cairo-dock-themes-manager.h"
#include "cairo-dock-dialog-manager.h"
#include "cairo-dock-gui-backend.h"
#include "cairo-dock-gui-commons.h"
#define CAIRO_DOCK_PLUGINS_EXTRAS_URL "http://extras.glx-dock.org"
extern CairoDockDesktopGeometry g_desktopGeometry;
void cairo_dock_update_desklet_widgets (CairoDesklet *pDesklet, GSList *pWidgetList)
{
CairoDockGroupKeyWidget *pGroupKeyWidget;
GtkWidget *pOneWidget;
pGroupKeyWidget = cairo_dock_gui_find_group_key_widget_in_list (pWidgetList, "Desklet", "locked");
g_return_if_fail (pGroupKeyWidget != NULL && pGroupKeyWidget->pSubWidgetList != NULL);
pOneWidget = pGroupKeyWidget->pSubWidgetList->data;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pOneWidget), pDesklet->bPositionLocked);
pGroupKeyWidget = cairo_dock_gui_find_group_key_widget_in_list (pWidgetList, "Desklet", "size");
g_return_if_fail (pGroupKeyWidget != NULL && pGroupKeyWidget->pSubWidgetList != NULL);
pOneWidget = pGroupKeyWidget->pSubWidgetList->data;
g_signal_handlers_block_matched (pOneWidget,
(GSignalMatchType) G_SIGNAL_MATCH_FUNC,
0, 0, NULL, _cairo_dock_set_value_in_pair, NULL);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (pOneWidget), pDesklet->container.iWidth);
g_signal_handlers_unblock_matched (pOneWidget,
(GSignalMatchType) G_SIGNAL_MATCH_FUNC,
0, 0, NULL, _cairo_dock_set_value_in_pair, NULL);
if (pGroupKeyWidget->pSubWidgetList->next != NULL)
{
pOneWidget = pGroupKeyWidget->pSubWidgetList->next->data;
g_signal_handlers_block_matched (pOneWidget,
(GSignalMatchType) G_SIGNAL_MATCH_FUNC,
0, 0, NULL, _cairo_dock_set_value_in_pair, NULL);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (pOneWidget), pDesklet->container.iHeight);
g_signal_handlers_unblock_matched (pOneWidget,
(GSignalMatchType) G_SIGNAL_MATCH_FUNC,
0, 0, NULL, _cairo_dock_set_value_in_pair, NULL);
}
int iRelativePositionX = (pDesklet->container.iWindowPositionX + pDesklet->container.iWidth/2 <= g_desktopGeometry.iXScreenWidth[CAIRO_DOCK_HORIZONTAL]/2 ? pDesklet->container.iWindowPositionX : pDesklet->container.iWindowPositionX - g_desktopGeometry.iXScreenWidth[CAIRO_DOCK_HORIZONTAL]);
int iRelativePositionY = (pDesklet->container.iWindowPositionY + pDesklet->container.iHeight/2 <= g_desktopGeometry.iXScreenHeight[CAIRO_DOCK_HORIZONTAL]/2 ? pDesklet->container.iWindowPositionY : pDesklet->container.iWindowPositionY - g_desktopGeometry.iXScreenHeight[CAIRO_DOCK_HORIZONTAL]);
pGroupKeyWidget = cairo_dock_gui_find_group_key_widget_in_list (pWidgetList, "Desklet", "x position");
g_return_if_fail (pGroupKeyWidget != NULL && pGroupKeyWidget->pSubWidgetList != NULL);
pOneWidget = pGroupKeyWidget->pSubWidgetList->data;
gtk_spin_button_set_value (GTK_SPIN_BUTTON (pOneWidget), iRelativePositionX);
pGroupKeyWidget = cairo_dock_gui_find_group_key_widget_in_list (pWidgetList, "Desklet", "y position");
g_return_if_fail (pGroupKeyWidget != NULL && pGroupKeyWidget->pSubWidgetList != NULL);
pOneWidget = pGroupKeyWidget->pSubWidgetList->data;
gtk_spin_button_set_value (GTK_SPIN_BUTTON (pOneWidget), iRelativePositionY);
pGroupKeyWidget = cairo_dock_gui_find_group_key_widget_in_list (pWidgetList, "Desklet", "rotation");
g_return_if_fail (pGroupKeyWidget != NULL && pGroupKeyWidget->pSubWidgetList != NULL);
pOneWidget = pGroupKeyWidget->pSubWidgetList->data;
gtk_range_set_value (GTK_RANGE (pOneWidget), pDesklet->fRotation/G_PI*180.);
}
void cairo_dock_update_desklet_visibility_widgets (CairoDesklet *pDesklet, GSList *pWidgetList)
{
CairoDockGroupKeyWidget *pGroupKeyWidget;
GtkWidget *pOneWidget;
gboolean bIsSticky = cairo_dock_desklet_is_sticky (pDesklet);
CairoDeskletVisibility iVisibility = pDesklet->iVisibility;
pGroupKeyWidget = cairo_dock_gui_find_group_key_widget_in_list (pWidgetList, "Desklet", "accessibility");
g_return_if_fail (pGroupKeyWidget != NULL && pGroupKeyWidget->pSubWidgetList != NULL);
pOneWidget = pGroupKeyWidget->pSubWidgetList->data;
gtk_combo_box_set_active (GTK_COMBO_BOX (pOneWidget), iVisibility);
pGroupKeyWidget = cairo_dock_gui_find_group_key_widget_in_list (pWidgetList, "Desklet", "sticky");
g_return_if_fail (pGroupKeyWidget != NULL && pGroupKeyWidget->pSubWidgetList != NULL);
pOneWidget = pGroupKeyWidget->pSubWidgetList->data;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pOneWidget), bIsSticky);
pGroupKeyWidget = cairo_dock_gui_find_group_key_widget_in_list (pWidgetList, "Desklet", "locked");
g_return_if_fail (pGroupKeyWidget != NULL && pGroupKeyWidget->pSubWidgetList != NULL);
pOneWidget = pGroupKeyWidget->pSubWidgetList->data;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pOneWidget), pDesklet->bPositionLocked);
}
void cairo_dock_update_is_detached_widget (gboolean bIsDetached, GSList *pWidgetList)
{
CairoDockGroupKeyWidget *pGroupKeyWidget;
GtkWidget *pOneWidget;
pGroupKeyWidget = cairo_dock_gui_find_group_key_widget_in_list (pWidgetList, "Desklet", "initially detached");
g_return_if_fail (pGroupKeyWidget != NULL && pGroupKeyWidget->pSubWidgetList != NULL);
pOneWidget = pGroupKeyWidget->pSubWidgetList->data;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pOneWidget), bIsDetached);
}
#define DISTANT_DIR "3.1.0"
gchar *cairo_dock_get_third_party_applets_link (void)
{
return g_strdup_printf (CAIRO_DOCK_PLUGINS_EXTRAS_URL"/"DISTANT_DIR);
}
/**
* Return absolute position of the bottom left corner of a widget to place a menu.
* use with @see cairo_dock_place_menu_at_position
* see @see cairo_dock_popup_menu_under_widget for an example
*/
GtkRequisition *cairo_dock_get_widget_bottom_position (GtkWidget *pWidget)
{
GtkRequisition *pPosition = g_new (GtkRequisition, 1);
gint dx = 0, dy = 0;
GtkRequisition req;
// Top left drawable window coordinates on screen. (inside decorations)
// We need to get the toplevel widget origin.
// Otherwise, it would give wrong results if called on the widget in a scrolled area.
// (drawable surface origin can even be out of the screen).
GtkWidget *pTopLevel = gtk_widget_get_toplevel (pWidget);
gdk_window_get_origin (gtk_widget_get_window (pTopLevel), &pPosition->width, &pPosition->height);
// Widget position inside the window.
gtk_widget_translate_coordinates (pWidget, pTopLevel, 0, 0, &dx, &dy);
// Widget height.
#if (GTK_MAJOR_VERSION < 3)
gtk_widget_size_request (pWidget, &req);
#else
gtk_widget_get_preferred_size (pWidget, &req, NULL);
#endif
pPosition->width += dx;
pPosition->height += dy + req.height;
return pPosition;
}
/**
* Convenient GtkMenuPositionFunc callback function to position menu.
* use with @see cairo_dock_get_widget_bottom_position
*/
void cairo_dock_place_menu_at_position (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, GtkRequisition *pPosition)
{
*push_in = TRUE;
if (pPosition != NULL)
{
*x = pPosition->width;
*y = pPosition->height;
}
}
/**
* Callback for the button-press-event that popup the given menu.
*/
void cairo_dock_popup_menu_under_widget (GtkWidget *pWidget, GtkMenu *pMenu)
{
GtkRequisition *pPosition = pWidget == NULL ? NULL : cairo_dock_get_widget_bottom_position (pWidget);
gtk_menu_popup (pMenu,
NULL,
NULL,
(GtkMenuPositionFunc) cairo_dock_place_menu_at_position,
pPosition,
0, // pEventButton->button
gtk_get_current_event_time ()); // pEventButton->time
if (pPosition != NULL)
g_free (pPosition);
}
|