1 /**
2 * This file is a part of the Cairo-Dock project
3 *
4 * Copyright : (C) see the 'copyright' file.
5 * E-mail    : see the 'copyright' file.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #define _BSD_SOURCE
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <glib/gi18n.h>
26 #include <glib/gstdio.h>
27 
28 #include "applet-struct.h"
29 #include "applet-notifications.h"
30 #include "applet-composite-manager.h"
31 
_on_answer(int iClickedButton,GtkWidget * pInteractiveWidget,gpointer data,CairoDialog * pDialog)32 static void _on_answer (int iClickedButton, GtkWidget *pInteractiveWidget, gpointer data, CairoDialog *pDialog)
33 {
34 	if (iClickedButton == 0 || iClickedButton == -1)  // ok or Enter
35 	{
36 		cd_toggle_composite ();
37 	}
38 }
39 
40 CD_APPLET_ON_CLICK_BEGIN
41 	if (myConfig.bAskBeforeSwitching)
42 	{
43 		gldi_dialog_show (D_("Toggle composite?"), myIcon, myContainer, 0, "same icon", NULL, (CairoDockActionOnAnswerFunc)_on_answer, NULL, NULL);
44 	}
45 	else
46 	{
47 		cd_toggle_composite ();
48 	}
49 CD_APPLET_ON_CLICK_END
50 
51 
_cd_show_desktop(void)52 static void _cd_show_desktop (void)
53 {
54 	gboolean bDesktopIsVisible = gldi_desktop_is_visible ();
55 	gldi_desktop_show_hide (! bDesktopIsVisible);
56 }
_cd_expose_windows(void)57 static void _cd_expose_windows (void)
58 {
59 	gldi_desktop_present_windows ();
60 }
_cd_expose_windows_idle(gpointer data)61 static gboolean _cd_expose_windows_idle (gpointer data)
62 {
63 	_cd_expose_windows ();
64 	return FALSE;
65 }
_cd_expose_desktops(void)66 static void _cd_expose_desktops (void)
67 {
68 	gldi_desktop_present_desktops ();
69 }
_cd_show_widget_layer(void)70 static void _cd_show_widget_layer (void)
71 {
72 	gldi_desktop_show_widget_layer ();
73 }
74 
75 CD_APPLET_ON_MIDDLE_CLICK_BEGIN
76 	switch (myConfig.iActionOnMiddleClick)
77 	{
78 
79 		case CD_EDIT_CONFIG:
80 		{
81 			cd_open_wm_config();
82 		}
83 		break;
84 		case CD_RELOAD_WM:
85 		{
86 			cd_reload_wm();
87 		}
88 		break;
89 		case CD_SHOW_DESKTOP:
90 		{
91 			_cd_show_desktop ();
92 		}
93 		break;
94 		case CD_EXPOSE_DESKTOPS:
95 		{
96 			_cd_expose_desktops ();
97 		}
98 		break;
99 		case CD_EXPOSE_WINDOWS:
100 		{
101 			// ok this is just crazy: if you call the Scale dbus method of Compiz before the middle button is released, it doesn't work.
102 			g_timeout_add (300, _cd_expose_windows_idle, NULL);
103 		}
104 		break;
105 		case CD_SHOW_WIDGET_LAYER:
106 		{
107 			_cd_show_widget_layer ();
108 		}
109 		break;
110 		default: // shouldn't happen.
111 			cd_warning ("problem in the config!");
112 		break;
113 	}
114 CD_APPLET_ON_MIDDLE_CLICK_END
115 
116 
117 CD_APPLET_ON_BUILD_MENU_BEGIN
118 	gchar *cLabel;
119 
120 	cLabel = (myConfig.iActionOnMiddleClick == CD_EDIT_CONFIG ? g_strdup_printf ("%s (%s)", D_("Edit Window-Manager settings"), D_("middle-click")) : g_strdup (D_("Edit Window-Manager settings")));
121 	CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel,
122 		GLDI_ICON_NAME_EDIT,
123 		cd_open_wm_config,
124 		CD_APPLET_MY_MENU);
125 	g_free (cLabel);
126 
127 	cLabel = (myConfig.iActionOnMiddleClick == CD_RELOAD_WM ? g_strdup_printf ("%s (%s)", D_("Reload Window-Manager"), D_("middle-click")) : g_strdup (D_("Reload Window-Manager")));
128 	CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel,
129 		GLDI_ICON_NAME_REFRESH,
130 		cd_reload_wm,
131 		CD_APPLET_MY_MENU);
132 	g_free (cLabel);
133 
134 	CD_APPLET_ADD_SEPARATOR_IN_MENU (CD_APPLET_MY_MENU);
135 
136 	cLabel = (myConfig.iActionOnMiddleClick == CD_SHOW_DESKTOP ? g_strdup_printf ("%s (%s)", D_("Show desktop"), D_("middle-click")) : g_strdup (D_("Show desktop")));
137 	CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel,
138 		MY_APPLET_SHARE_DATA_DIR"/../shared-files/images/show-desktop.svg",
139 		_cd_show_desktop,
140 		CD_APPLET_MY_MENU);
141 	g_free (cLabel);
142 
143 	if (gldi_desktop_can_present_desktops ())
144 	{
145 		cLabel = (myConfig.iActionOnMiddleClick == CD_EXPOSE_DESKTOPS ? g_strdup_printf ("%s (%s)", D_("Expose all the desktops"), D_("middle-click")) : g_strdup (D_("Expose all the desktops")));
146 		CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel,
147 			MY_APPLET_SHARE_DATA_DIR"/../shared-files/images/expose-desktops.svg",
148 			_cd_expose_desktops,
149 			CD_APPLET_MY_MENU);
150 		g_free (cLabel);
151 	}
152 	if (gldi_desktop_can_present_windows ())
153 	{
154 		cLabel = (myConfig.iActionOnMiddleClick == CD_EXPOSE_WINDOWS ? g_strdup_printf ("%s (%s)", D_("Expose all the windows"), D_("middle-click")) : g_strdup (D_("Expose all the windows")));
155 		CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel,
156 			MY_APPLET_SHARE_DATA_DIR"/../shared-files/images/expose-windows.svg",
157 			_cd_expose_windows,
158 			CD_APPLET_MY_MENU);
159 		g_free (cLabel);
160 	}
161 	if (gldi_desktop_can_show_widget_layer ())
162 	{
163 		cLabel = (myConfig.iActionOnMiddleClick == CD_SHOW_WIDGET_LAYER ? g_strdup_printf ("%s (%s)", D_("Show the Widget Layer"), D_("middle-click")) : g_strdup (D_("Show the Widget Layer")));
164 		CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel,
165 			GLDI_ICON_NAME_LEAVE_FULLSCREEN,
166 			_cd_show_widget_layer,
167 			CD_APPLET_MY_MENU);
168 		g_free (cLabel);
169 	}
170 CD_APPLET_ON_BUILD_MENU_END
171 
172 
cd_on_keybinding_pull(const char * keystring,gpointer user_data)173 void cd_on_keybinding_pull (const char *keystring, gpointer user_data)
174 {
175 	cd_toggle_composite ();
176 }
177