#include #include #include #include #include #include #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_file("rcm-client.ui"); global->window = GTK_WINDOW(gtk_builder_get_object(global->builder, "main_window")); g_signal_connect(global->window, "destroy", G_CALLBACK(gtk_main_quit), NULL); 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; }