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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <gtk/gtk.h>
#include "generated.h"
#include "shared.h"
#include "rcm-client-main.h"
#include "rcm-client-hardware-list.h"
#include "rcm-client-receive.h"
#include "rcm-client-advanced.h"
#define WINDOW_WIDTH 300
#define WINDOW_HEIGHT 300
static GDBusObjectManager *mgr = NULL;
struct global_variables *global;
void
poke_objects()
{
GList *objects;
GList *l;
GDBusObjectManager *manager = mgr;
objects = g_dbus_object_manager_get_objects (manager);
for (l = objects; l != NULL; l = l->next)
{
GDBusInterface *interface;
interface = g_dbus_object_get_interface(G_DBUS_OBJECT(l->data),
"org.gnome.RemoteControlManager.Device");
if (!interface) {
g_print("That's weird, an object which is not a device...\n");
continue;
}
RCDevice *object = RCDEVICE(interface);
printf("DBus object %s\n", g_dbus_object_get_object_path(G_DBUS_OBJECT(l->data)));
printf("\tDriver name is: %s\n", rcdevice_get_driver_name(object));
printf("\tKeymap name is: %s\n", rcdevice_get_kernel_keymap_name(object));
g_object_unref(interface);
}
g_list_free_full (objects, g_object_unref);
}
static void
on_object_added(GDBusObjectManager *manager,
GDBusObject *object,
gpointer user_data)
{
g_print("Added object at %s\n", g_dbus_object_get_object_path(object));
rcng_client_hardware_list_add(object);
}
static void
on_object_removed(GDBusObjectManager *manager,
GDBusObject *object,
gpointer user_data)
{
g_print("Removed object at %s\n", g_dbus_object_get_object_path(object));
rcng_client_hardware_list_remove(object);
}
static void
on_signal(GDBusObjectManagerClient *manager,
GDBusObjectProxy *object_proxy,
GDBusProxy *interface_proxy,
gchar *sender_name,
gchar *signal_name,
GVariant *parameters,
gpointer user_data)
{
gchar *protocol;
guint64 scancode;
gchar *keycode;
gchar *event;
g_print("Signal %s received for obj %s\n", signal_name,
g_dbus_object_get_object_path(G_DBUS_OBJECT(object_proxy)));
if (!strcmp(signal_name, "KeyReleased")) {
g_variant_get(parameters, "(s)", &keycode);
rcng_client_receive_key_released(G_DBUS_OBJECT(object_proxy), keycode);
g_free(keycode);
} else if (!strcmp(signal_name, "KeyPressed")) {
g_variant_get(parameters, "(sts)", &protocol, &scancode, &keycode);
rcng_client_receive_key_pressed(G_DBUS_OBJECT(object_proxy), protocol, scancode, keycode);
g_free(protocol);
g_free(keycode);
} else if (!strcmp(signal_name, "Event")) {
g_variant_get(parameters, "(s)", &event);
advanced_receive_event(event);
g_free(event);
}
}
static void
on_owner_change(GDBusObjectManager *manager, gpointer user_data)
{
g_print("Owner changed, now: %s\n", g_dbus_object_manager_client_get_name_owner(G_DBUS_OBJECT_MANAGER_CLIENT(manager)));
if (!g_dbus_object_manager_client_get_name_owner(G_DBUS_OBJECT_MANAGER_CLIENT(manager)))
rcng_client_hardware_list_update_status("Server not running...\n");
else
rcng_client_hardware_list_update_status("No hardware connected...");
}
static void
manager_ready_cb(GObject *source, GAsyncResult *res, gpointer user_data)
{
GError *error = NULL;
GList *objects;
GList *l;
mgr = object_manager_client_new_for_bus_finish(res, &error);
if (!mgr) {
gchar *msg;
msg = g_strdup_printf("Error creating object manager client: %s",
error->message);
rcng_client_hardware_list_update_status(msg);
g_free(msg);
g_error_free(error);
return;
}
g_signal_connect(mgr, "object-added", G_CALLBACK(on_object_added), NULL);
g_signal_connect(mgr, "object-removed", G_CALLBACK(on_object_removed), NULL);
g_signal_connect(mgr, "interface-proxy-signal", G_CALLBACK(on_signal), NULL);
g_signal_connect(mgr, "notify::name-owner", G_CALLBACK(on_owner_change), NULL);
on_owner_change(mgr, NULL);
g_print("Object manager at %s\n", g_dbus_object_manager_get_object_path(mgr));
objects = g_dbus_object_manager_get_objects(mgr);
for (l = objects; l != NULL; l = l->next)
rcng_client_hardware_list_add(G_DBUS_OBJECT(l->data));
g_list_free_full (objects, g_object_unref);
}
GtkWidget *
create_header_button(GtkHeaderBar *header, const gchar *tooltip,
const gchar *icon_name, gboolean end, GCallback callback,
gpointer user_data)
{
GtkWidget *button;
button = gtk_button_new_from_icon_name(icon_name, GTK_ICON_SIZE_BUTTON);
if (tooltip)
gtk_widget_set_tooltip_text(button, tooltip);
g_signal_connect(button, "clicked", callback, user_data);
gtk_widget_set_valign(button, GTK_ALIGN_CENTER);
gtk_widget_show_all(button);
if (!header)
header = GTK_HEADER_BAR(gtk_builder_get_object(global->builder, "main_headerbar"));
if (end)
gtk_header_bar_pack_end(header, button);
else
gtk_header_bar_pack_start(header, button);
return button;
}
void
cbox_add_all_protocols(GtkComboBoxText *cbox)
{
unsigned i;
if (!cbox)
return;
gtk_combo_box_text_remove_all(cbox);
for (i = 0; rc_protocols[i]; i++)
gtk_combo_box_text_append(cbox, NULL, rc_protocols[i]);
gtk_combo_box_set_active(GTK_COMBO_BOX(cbox), 0);
}
void
cbox_add_all_keycodes(GtkComboBoxText *cbox)
{
unsigned i;
if (!cbox)
return;
gtk_combo_box_text_remove_all(cbox);
for (i = 0; linux_input_keycodes[i].name; i++)
gtk_combo_box_text_append(cbox, NULL, linux_input_keycodes[i].name);
gtk_combo_box_set_active(GTK_COMBO_BOX(cbox), 0);
}
gulong
_g_signal_replace(gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer data, GConnectFlags flags)
{
g_signal_handlers_disconnect_matched(instance, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, c_handler, NULL);
return g_signal_connect_data(instance, detailed_signal, c_handler, data, NULL, flags);
}
gulong
_g_signal_replace_id(const gchar *widget_id, const gchar *detailed_signal, GCallback c_handler, gpointer data, GConnectFlags flags)
{
GObject *w = G_OBJECT(gtk_builder_get_object(global->builder, widget_id));
return w ? _g_signal_replace(w, detailed_signal, c_handler, data, flags) : 0;
}
int main(int argc, char *argv[])
{
GtkCssProvider *css;
GdkScreen *screen;
global = g_malloc(sizeof(*global));
gtk_init (&argc, &argv);
css = gtk_css_provider_new();
gtk_css_provider_load_from_path(css, "rcm.css", NULL);
screen = gdk_display_get_default_screen(gdk_display_get_default());
gtk_style_context_add_provider_for_screen(screen, GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref(css);
global->builder = gtk_builder_new_from_resource("/org/gnome/RemoteControlManager/rcm-client.ui");
gtk_builder_connect_signals(global->builder, NULL);
global->window = GTK_WINDOW(gtk_builder_get_object(global->builder, "main_window"));
global->stack = GTK_STACK(gtk_builder_get_object(global->builder, "main_stack"));
gtk_widget_show_all(GTK_WIDGET(global->window));
object_manager_client_new_for_bus(G_BUS_TYPE_SESSION,
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
"org.gnome.RemoteControlManager",
"/org/gnome/RemoteControlManager",
NULL, manager_ready_cb, NULL);
gtk_main();
return 0;
}
|