Remmina - The GTK+ Remote Desktop Client  v1.4.33
Remmina is a remote desktop client written in GTK+, aiming to be useful for system administrators and travellers, who need to work with lots of remote computers in front of either large monitors or tiny netbooks. Remmina supports multiple network protocols in an integrated and consistent user interface. Currently RDP, VNC, NX, XDMCP and SSH are supported.
remmina_widget_pool.c
Go to the documentation of this file.
1 /*
2  * Remmina - The GTK+ Remote Desktop Client
3  * Copyright (C) 2009 - Vic Lee
4  * Copyright (C) 2014-2015 Antenore Gatta, Fabio Castelli, Giovanni Panozzo
5  * Copyright (C) 2016-2023 Antenore Gatta, Giovanni Panozzo
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (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  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  * In addition, as a special exception, the copyright holders give
23  * permission to link the code of portions of this program with the
24  * OpenSSL library under certain conditions as described in each
25  * individual source file, and distribute linked combinations
26  * including the two.
27  * You must obey the GNU General Public License in all respects
28  * for all of the code used other than OpenSSL. * If you modify
29  * file(s) with this exception, you may extend this exception to your
30  * version of the file(s), but you are not obligated to do so. * If you
31  * do not wish to do so, delete this exception statement from your
32  * version. * If you delete this exception statement from all source
33  * files in the program, then also delete it here.
34  *
35  */
36 
37 #include <gmodule.h>
38 #include "remmina_public.h"
39 #include "remmina_widget_pool.h"
41 
42 static GPtrArray *remmina_widget_pool = NULL;
43 
45 {
46  TRACE_CALL(__func__);
47  remmina_widget_pool = g_ptr_array_new();
48 }
49 
50 static void remmina_widget_pool_on_widget_destroy(GtkWidget *widget, gpointer data)
51 {
52  TRACE_CALL(__func__);
53  g_ptr_array_remove(remmina_widget_pool, widget);
54 }
55 
56 void remmina_widget_pool_register(GtkWidget *widget)
57 {
58  TRACE_CALL(__func__);
59  g_ptr_array_add(remmina_widget_pool, widget);
60  g_signal_connect(G_OBJECT(widget), "destroy", G_CALLBACK(remmina_widget_pool_on_widget_destroy), NULL);
61 }
62 
63 GtkWidget*
64 remmina_widget_pool_find(GType type, const gchar *tag)
65 {
66  TRACE_CALL(__func__);
67  GtkWidget *widget;
68  gint i;
69 
70  if (remmina_widget_pool == NULL)
71  return NULL;
72 
73  for (i = 0; i < remmina_widget_pool->len; i++) {
74  widget = GTK_WIDGET(g_ptr_array_index(remmina_widget_pool, i));
75  if (!G_TYPE_CHECK_INSTANCE_TYPE(widget, type))
76  continue;
77  if (tag && g_strcmp0((const gchar*)g_object_get_data(G_OBJECT(widget), "tag"), tag) != 0)
78  continue;
79  return widget;
80  }
81  return NULL;
82 }
83 
84 GtkWidget*
85 remmina_widget_pool_find_by_window(GType type, GdkWindow *window)
86 {
87  TRACE_CALL(__func__);
88  GtkWidget *widget;
89  gint i;
90  GdkWindow *parent;
91 
92  if (window == NULL || remmina_widget_pool == NULL)
93  return NULL;
94 
95  for (i = 0; i < remmina_widget_pool->len; i++) {
96  widget = GTK_WIDGET(g_ptr_array_index(remmina_widget_pool, i));
97  if (!G_TYPE_CHECK_INSTANCE_TYPE(widget, type))
98  continue;
99  /* gdk_window_get_toplevel won’t work here, if the window is an embedded client. So we iterate the window tree */
100  for (parent = window; parent && parent != GDK_WINDOW_ROOT; parent = gdk_window_get_parent(parent)) {
101  if (gtk_widget_get_window(widget) == parent)
102  return widget;
103  }
104  }
105  return NULL;
106 }
107 
109 {
110  TRACE_CALL(__func__);
111  GtkWidget *widget;
112  gint i;
113  gint n = 0;
114  GPtrArray *wpcpy = NULL;
115 
116  if (remmina_widget_pool == NULL)
117  return 0;
118 
119  /* Make a copy of remmina_widget_pool, so we can survive when callback()
120  * remove an element from remmina_widget_pool */
121 
122  wpcpy = g_ptr_array_sized_new(remmina_widget_pool->len);
123 
124  for (i = 0; i < remmina_widget_pool->len; i++)
125  g_ptr_array_add(wpcpy, g_ptr_array_index(remmina_widget_pool, i));
126 
127  /* Scan the remmina_widget_pool and call callbac() on every element */
128  for (i = 0; i < wpcpy->len; i++) {
129  widget = GTK_WIDGET(g_ptr_array_index(wpcpy, i));
130  if (callback(widget, data))
131  n++;
132  }
133 
134  /* Free the copy */
135  g_ptr_array_unref(wpcpy);
136  return n;
137 }
138 
140 {
141  TRACE_CALL(__func__);
142  return remmina_widget_pool->len;
143 }
144 
GtkWidget * remmina_widget_pool_find_by_window(GType type, GdkWindow *window)
void remmina_widget_pool_register(GtkWidget *widget)
G_BEGIN_DECLS typedef gboolean(* RemminaWidgetPoolForEachFunc)(GtkWidget *widget, gpointer data)
gint remmina_widget_pool_count()
void remmina_widget_pool_init(void)
static GPtrArray * remmina_widget_pool
gint remmina_widget_pool_foreach(RemminaWidgetPoolForEachFunc callback, gpointer data)
static void remmina_widget_pool_on_widget_destroy(GtkWidget *widget, gpointer data)
GtkWidget * remmina_widget_pool_find(GType type, const gchar *tag)