File: wrapper-plug.c

package info (click to toggle)
xfce4-panel 4.20.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 17,056 kB
  • sloc: ansic: 61,551; sh: 5,515; makefile: 1,330; python: 128; xml: 101; sed: 16
file content (194 lines) | stat: -rw-r--r-- 4,819 bytes parent folder | download | duplicates (3)
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
/*
 * Copyright (C) 2022 Gaƫl Bonithon <gael@xfce.org>
 *
 * 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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "wrapper-plug.h"

#ifdef ENABLE_X11
#include "wrapper-plug-x11.h"
#endif

#ifdef HAVE_GTK_LAYER_SHELL
#include "wrapper-plug-wayland.h"

#include <gtk-layer-shell.h>
#endif

#include "common/panel-private.h"



G_DEFINE_INTERFACE (WrapperPlug, wrapper_plug, GTK_TYPE_WINDOW)



static void
wrapper_plug_default_init (WrapperPlugInterface *iface)
{
}



GtkWidget *
wrapper_plug_new (gulong socket_id,
                  gint unique_id,
                  GDBusProxy *proxy,
                  GError **error)
{
  panel_return_val_if_fail (G_IS_DBUS_PROXY (proxy), NULL);
  panel_return_val_if_fail (error != NULL && *error == NULL, NULL);

#ifdef ENABLE_X11
  if (WINDOWING_IS_X11 ())
    return wrapper_plug_x11_new (socket_id, proxy);
#endif
#ifdef HAVE_GTK_LAYER_SHELL
  if (gtk_layer_is_supported ())
    return wrapper_plug_wayland_new (unique_id, proxy, error);
#endif

  g_set_error (error, 0, 0, "Running plugins as external is not supported on this windowing environment");

  return NULL;
}



void
wrapper_plug_proxy_provider_signal (WrapperPlug *plug,
                                    XfcePanelPluginProviderSignal provider_signal,
                                    XfcePanelPluginProvider *provider)
{
  panel_return_if_fail (WRAPPER_IS_PLUG (plug));
  panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));

  WRAPPER_PLUG_GET_IFACE (plug)->proxy_provider_signal (plug, provider_signal, provider);
}



void
wrapper_plug_proxy_remote_event_result (WrapperPlug *plug,
                                        guint handle,
                                        gboolean result)
{
  panel_return_if_fail (WRAPPER_IS_PLUG (plug));

  WRAPPER_PLUG_GET_IFACE (plug)->proxy_remote_event_result (plug, handle, result);
}



void
wrapper_plug_set_background_color (WrapperPlug *plug,
                                   const gchar *color)
{
  panel_return_if_fail (WRAPPER_IS_PLUG (plug));

  WRAPPER_PLUG_GET_IFACE (plug)->set_background_color (plug, color);
}



void
wrapper_plug_set_background_image (WrapperPlug *plug,
                                   const gchar *image)
{
  panel_return_if_fail (WRAPPER_IS_PLUG (plug));

  WRAPPER_PLUG_GET_IFACE (plug)->set_background_image (plug, image);
}



void
wrapper_plug_set_monitor (WrapperPlug *plug,
                          gint monitor)
{
  panel_return_if_fail (WRAPPER_IS_PLUG (plug));

  WRAPPER_PLUG_GET_IFACE (plug)->set_monitor (plug, monitor);
}



void
wrapper_plug_set_geometry (WrapperPlug *plug,
                           const GdkRectangle *geometry)
{
  panel_return_if_fail (WRAPPER_IS_PLUG (plug));

  WRAPPER_PLUG_GET_IFACE (plug)->set_geometry (plug, geometry);
}



void
wrapper_plug_proxy_method_call_sync (GDBusProxy *proxy,
                                     const gchar *method,
                                     GVariant *variant)
{
  GVariant *ret;
  GError *error = NULL;

  ret = g_dbus_proxy_call_sync (proxy, method, variant, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
  if (ret != NULL)
    g_variant_unref (ret);
  else
    {
      g_warning ("%s call failed: %s", method, error->message);
      g_error_free (error);
    }
}



static void
wrapper_plug_proxy_method_call_finish (GObject *source_object,
                                       GAsyncResult *res,
                                       gpointer data)
{
  GVariant *ret;
  GError *error = NULL;
  gchar *method = data;

  ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
  if (ret != NULL)
    g_variant_unref (ret);
  else
    {
      g_warning ("%s call failed: %s", method, error->message);
      g_error_free (error);
    }

  g_free (method);
}



void
wrapper_plug_proxy_method_call (GDBusProxy *proxy,
                                const gchar *method,
                                GVariant *variant)
{
  g_dbus_proxy_call (proxy, method, variant, G_DBUS_CALL_FLAGS_NONE, -1, NULL,
                     wrapper_plug_proxy_method_call_finish, g_strdup (method));
}