diff options
-rw-r--r-- | RemoteControlManager.xml | 6 | ||||
-rw-r--r-- | rcm-client-receive.c | 28 | ||||
-rw-r--r-- | rcm-server-keymap.c | 56 | ||||
-rw-r--r-- | rcm-server-keymap.h | 5 | ||||
-rw-r--r-- | rcm-server-main.c | 18 |
5 files changed, 67 insertions, 46 deletions
diff --git a/RemoteControlManager.xml b/RemoteControlManager.xml index df8f2b2..dc6d4d5 100644 --- a/RemoteControlManager.xml +++ b/RemoteControlManager.xml @@ -3,10 +3,12 @@ <interface name='org.gnome.RemoteControlManager.Device'> <annotation name="org.gtk.GDBus.C.Name" value="RCDevice"/> <method name='ListKeymaps'> - <arg type='as' name='keymap_names' direction='out'/> + <arg type='as' name='keymap_ids' direction='out'/> </method> <method name='GetKeymap'> - <arg type='s' name='keymap_name' direction='in'/> + <arg type='s' name='keymap_id' direction='in'/> + <arg type='s' name='keymap_name' direction='out'/> + <arg type='s' name='keymap_description' direction='out'/> <arg type='q' name='keymap_width' direction='out'/> <arg type='q' name='keymap_height' direction='out'/> <arg type='aa{sv}' name='keymap_entries' direction='out'/> diff --git a/rcm-client-receive.c b/rcm-client-receive.c index 8f43c7a..4f21f78 100644 --- a/rcm-client-receive.c +++ b/rcm-client-receive.c @@ -23,7 +23,9 @@ struct keymap_entry { }; struct remote { + char *id; char *name; + char *description; guint16 width; guint16 height; GList *buttons; @@ -691,18 +693,20 @@ void rcng_client_receive_keypress(GDBusObject *obj, const gchar *keycode, bool p } static struct remote * -get_keymap(RCDevice *object, const gchar *keymap_name) +get_keymap(RCDevice *object, const gchar *keymap_id) { struct remote *remote; GVariant *keymap_entries = NULL; GVariant *layout_entries = NULL; remote = g_malloc0(sizeof(*remote)); - remote->name = strdup(keymap_name); + remote->id = strdup(keymap_id); - rcdevice_call_get_keymap_sync(object, keymap_name, &remote->width, - &remote->height, &keymap_entries, - &layout_entries, NULL, NULL); + rcdevice_call_get_keymap_sync(object, keymap_id, + &remote->name, &remote->description, + &remote->width, &remote->height, + &keymap_entries, &layout_entries, + NULL, NULL); g_assert(g_variant_is_of_type(keymap_entries, G_VARIANT_TYPE("aa{sv}"))); g_assert(g_variant_is_of_type(layout_entries, G_VARIANT_TYPE("aa{sv}"))); @@ -713,7 +717,7 @@ get_keymap(RCDevice *object, const gchar *keymap_name) remote->widget = fixed; GtkWidget *frame; - frame = gtk_frame_new(keymap_name); + frame = gtk_frame_new(remote->name); gtk_widget_set_name(gtk_frame_get_label_widget(GTK_FRAME(frame)), "RemoteControlClientRemoteLabel"); gtk_widget_set_name(frame, "RemoteControlClientRemoteFrame"); gtk_fixed_put(GTK_FIXED(fixed), frame, 0, 0); @@ -851,20 +855,20 @@ void rcng_client_receive_init_ui(GDBusObject *new_hw) if (!interface) return; - gchar **keymaps = NULL; + gchar **keymap_ids = NULL; RCDevice *object = RCDEVICE(interface); - rcdevice_call_list_keymaps_sync(object, &keymaps, NULL, NULL); - for (i = 0; keymaps[i]; i++) { + rcdevice_call_list_keymaps_sync(object, &keymap_ids, NULL, NULL); + for (i = 0; keymap_ids[i]; i++) { struct remote *remote; - g_print("Fetching keymap: %s\n", keymaps[i]); - remote = get_keymap(object, keymaps[i]); + g_print("Fetching keymap: %s\n", keymap_ids[i]); + remote = get_keymap(object, keymap_ids[i]); state.remotes = g_list_prepend(state.remotes, remote); gtk_grid_attach(GTK_GRID(rgrid), remote->widget, i, 1, 1, 1); } - g_free(keymaps); + g_free(keymap_ids); gtk_widget_show_all(scrollda); } diff --git a/rcm-server-keymap.c b/rcm-server-keymap.c index 3231ed2..d2a01c8 100644 --- a/rcm-server-keymap.c +++ b/rcm-server-keymap.c @@ -163,8 +163,8 @@ keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap, if (!keymap->name) return -ENOMEM; } else if (!strcasecmp(p, "Description")) { - keymap->desc = strdup(tmp); - if (!keymap->desc) + keymap->description = strdup(tmp); + if (!keymap->description) return -ENOMEM; } break; @@ -315,7 +315,7 @@ keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap, } static struct keymap * -keymap_read(int dfd, const char *name) +keymap_read(int dfd, const char *filename) { _cleanup_close_ int fd = -1; _cleanup_fclose_ FILE *fp = NULL; @@ -326,46 +326,51 @@ keymap_read(int dfd, const char *name) size_t buf_size = 0; int r; - if (dfd < 0 || !name) - return NULL; + if (dfd < 0 || !filename) + goto out; - fd = openat(dfd, name, O_RDONLY); + fd = openat(dfd, filename, O_RDONLY); if (fd < 0) - return NULL; + goto out; fp = fdopen(fd, "r"); if (!fp) - return NULL; + goto out; fd = -1; - printf("Parsing keymap %s...\n", name); + printf("Parsing keymap %s...\n", filename); r = keymap_parse(fp, &line, &buf_size, NULL, &rows, &cols, &keycode_count); if (r < 0) - return NULL; + goto out; keymap = zmalloc(sizeof(*keymap) + sizeof(struct keycode) * keycode_count); if (!keymap) - return NULL; + goto out; + + keymap->id = strdup(filename); + if (!keymap->id) + goto out; keymap->layout = zmalloc(sizeof(struct keycode *) * cols * rows); - if (!keymap->layout) { - free(keymap); - return NULL; - } + if (!keymap->layout) + goto out; r = keymap_parse(fp, &line, &buf_size, keymap, NULL, NULL, NULL); - if (r < 0) { - free(keymap->layout); - free(keymap); - return NULL; - } + if (r < 0) + goto out; printf("\tKeymap added\n"); - printf("\tDescription: %s\n", keymap->desc); + printf("\tID: %s\n", keymap->id); printf("\tName: %s\n", keymap->name); + printf("\tDescription: %s\n", keymap->description); printf("\tMappings: %u entries\n", keycode_count); printf("\tLayout: %u rows x %u cols = %u entries\n", rows, cols, rows * cols); return keymap; + +out: + if (keymap) + keymap_free(keymap); + return NULL; } static int @@ -389,7 +394,7 @@ keymaps_load_dir(struct device *device, const char *path) case DT_REG: case DT_LNK: case DT_UNKNOWN: - keymap = find_keymap_by_name(device, dent->d_name); + keymap = find_keymap_by_id(device, dent->d_name); if (keymap) continue; keymap = keymap_read(dfd, dent->d_name); @@ -424,17 +429,18 @@ keymap_free(struct keymap *keymap) { free(keymap->layout); free(keymap->name); - free(keymap->desc); + free(keymap->description); + free(keymap->id); free(keymap); } struct keymap * -find_keymap_by_name(struct device *dev, const char *name) +find_keymap_by_id(struct device *dev, const char *id) { struct keymap *keymap; list_for_each_entry(keymap, &dev->keymaps, list) - if (!strcmp(keymap->name, name)) + if (!strcmp(keymap->id, id)) return keymap; return NULL; diff --git a/rcm-server-keymap.h b/rcm-server-keymap.h index 8676fbc..03badb1 100644 --- a/rcm-server-keymap.h +++ b/rcm-server-keymap.h @@ -8,8 +8,9 @@ struct keycode { }; struct keymap { + char *id; char *name; - char *desc; + char *description; uint16_t rows; uint16_t cols; struct list_head list; @@ -18,7 +19,7 @@ struct keymap { struct keycode keycodes[]; }; -struct keymap *find_keymap_by_name(struct device *dev, const char *name); +struct keymap *find_keymap_by_id(struct device *dev, const char *id); int keymaps_load(struct device *device); diff --git a/rcm-server-main.c b/rcm-server-main.c index 572d5c9..2a3266f 100644 --- a/rcm-server-main.c +++ b/rcm-server-main.c @@ -75,7 +75,7 @@ method_listkeymaps(sd_bus_message *m, void *userdata, sd_bus_error *error) list_for_each_entry(keymap, &dev->keymaps, list) { printf("Listing keymaps for %s: %s\n", dev->name, keymap->name); - r = sd_bus_message_append(reply, "s", keymap->name); + r = sd_bus_message_append(reply, "s", keymap->id); if (r < 0) goto out; } @@ -101,7 +101,7 @@ method_getkeymap(sd_bus_message *m, void *userdata, sd_bus_error *error) struct manager *mgr = userdata; struct device *dev; struct keymap *keymap; - const char *name; + const char *id; int r; unsigned i; @@ -111,13 +111,13 @@ method_getkeymap(sd_bus_message *m, void *userdata, sd_bus_error *error) return -EINVAL; } - r = sd_bus_message_read(m, "s", &name); + r = sd_bus_message_read(m, "s", &id); if (r < 0) { fprintf(stderr, "Failed to parse parameters: %s\n", strerror(-r)); return r; } - keymap = find_keymap_by_name(dev, name); + keymap = find_keymap_by_id(dev, id); if (!keymap) { sd_bus_error_set_const(error, "org.gnome.RemoteControlManager.InvalidKeymap", "Sorry, unknown keymap"); return -EINVAL; @@ -127,6 +127,14 @@ method_getkeymap(sd_bus_message *m, void *userdata, sd_bus_error *error) if (r < 0) goto out; + r = sd_bus_message_append(reply, "s", keymap->name); + if (r < 0) + goto out; + + r = sd_bus_message_append(reply, "s", keymap->description); + if (r < 0) + goto out; + r = sd_bus_message_append(reply, "q", keymap->cols); if (r < 0) goto out; @@ -190,7 +198,7 @@ static const sd_bus_vtable device_vtable[] = { SD_BUS_PROPERTY("KernelKeymapName", "s", property_get, 0, 0), SD_BUS_PROPERTY("HardwareType", "s", property_get, 0, 0), SD_BUS_METHOD("ListKeymaps", NULL, "as", method_listkeymaps, SD_BUS_VTABLE_UNPRIVILEGED), - SD_BUS_METHOD("GetKeymap", "s", "qqaa{sv}aa{sv}", method_getkeymap, SD_BUS_VTABLE_UNPRIVILEGED), + SD_BUS_METHOD("GetKeymap", "s", "ssqqaa{sv}aa{sv}", method_getkeymap, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_SIGNAL("KeyPressed", "s", 0), SD_BUS_SIGNAL("KeyReleased", "s", 0), SD_BUS_VTABLE_END |