Remmina - The GTK+ Remote Desktop Client  v1.4.2
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-2020 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 <gtk/gtk.h>
38 #include <gmodule.h>
39 #include "remmina_public.h"
40 #include "remmina_widget_pool.h"
42 
43 static GPtrArray *remmina_widget_pool = NULL;
44 
46 {
47  TRACE_CALL(__func__);
48  remmina_widget_pool = g_ptr_array_new();
49 }
50 
51 static void remmina_widget_pool_on_widget_destroy(GtkWidget *widget, gpointer data)
52 {
53  TRACE_CALL(__func__);
54  g_ptr_array_remove(remmina_widget_pool, widget);
55 }
56 
57 void remmina_widget_pool_register(GtkWidget *widget)
58 {
59  TRACE_CALL(__func__);
60  g_ptr_array_add(remmina_widget_pool, widget);
61  g_signal_connect(G_OBJECT(widget), "destroy", G_CALLBACK(remmina_widget_pool_on_widget_destroy), NULL);
62 }
63 
64 GtkWidget*
65 remmina_widget_pool_find(GType type, const gchar *tag)
66 {
67  TRACE_CALL(__func__);
68  GtkWidget *widget;
69  gint i;
70 
71  if (remmina_widget_pool == NULL)
72  return NULL;
73 
74  for (i = 0; i < remmina_widget_pool->len; i++) {
75  widget = GTK_WIDGET(g_ptr_array_index(remmina_widget_pool, i));
76  if (!G_TYPE_CHECK_INSTANCE_TYPE(widget, type))
77  continue;
78  if (tag && g_strcmp0((const gchar*)g_object_get_data(G_OBJECT(widget), "tag"), tag) != 0)
79  continue;
80  return widget;
81  }
82  return NULL;
83 }
84 
85 GtkWidget*
86 remmina_widget_pool_find_by_window(GType type, GdkWindow *window)
87 {
88  TRACE_CALL(__func__);
89  GtkWidget *widget;
90  gint i;
91  GdkWindow *parent;
92 
93  if (window == NULL || remmina_widget_pool == NULL)
94  return NULL;
95 
96  for (i = 0; i < remmina_widget_pool->len; i++) {
97  widget = GTK_WIDGET(g_ptr_array_index(remmina_widget_pool, i));
98  if (!G_TYPE_CHECK_INSTANCE_TYPE(widget, type))
99  continue;
100  /* gdk_window_get_toplevel won’t work here, if the window is an embedded client. So we iterate the window tree */
101  for (parent = window; parent && parent != GDK_WINDOW_ROOT; parent = gdk_window_get_parent(parent)) {
102  if (gtk_widget_get_window(widget) == parent)
103  return widget;
104  }
105  }
106  return NULL;
107 }
108 
110 {
111  TRACE_CALL(__func__);
112  GtkWidget *widget;
113  gint i;
114  gint n = 0;
115  GPtrArray *wpcpy = NULL;
116 
117  if (remmina_widget_pool == NULL)
118  return 0;
119 
120  /* Make a copy of remmina_widget_pool, so we can survive when callback()
121  * remove an element from remmina_widget_pool */
122 
123  wpcpy = g_ptr_array_sized_new(remmina_widget_pool->len);
124 
125  for (i = 0; i < remmina_widget_pool->len; i++)
126  g_ptr_array_add(wpcpy, g_ptr_array_index(remmina_widget_pool, i));
127 
128  /* Scan the remmina_widget_pool and call callbac() on every element */
129  for (i = 0; i < wpcpy->len; i++) {
130  widget = GTK_WIDGET(g_ptr_array_index(wpcpy, i));
131  if (callback(widget, data))
132  n++;
133  }
134 
135  /* Free the copy */
136  g_ptr_array_unref(wpcpy);
137  return n;
138 }
139 
141 {
142  TRACE_CALL(__func__);
143  return remmina_widget_pool->len;
144 }
145 
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)