summaryrefslogtreecommitdiff
path: root/src/lib/ecore_drm
diff options
context:
space:
mode:
authorJengHyun Kang <jhyuni.kang@samsung.com>2016-01-04 08:47:43 -0500
committerChris Michael <cpmichael@osg.samsung.com>2016-01-04 08:47:58 -0500
commitb3dc27345a59dc21b115fe55bb15e7af092eacbe (patch)
tree8f66f5941ab4efd09eaadb2cfca12825f09da55a /src/lib/ecore_drm
parentfe70f0c080d2f168b5674cd4aa804ec95617739d (diff)
ecore-drm: Add a new API for keymap cache
Summary: Originally, each keyboard devices could have their own keymap. The one keyboard's keymap could different with others. But for this, Ecore_Drm compile a new keymap when a keyboard is connected. But this is a burden for some people who doesn't manage keymap for each keyboard. They want to maintain only one keymap for system. So, I added cached context/keymap and just ref/unref for each keyboard device. People who want to different keymap for each keyboard just do not set cached context/keymap. Then Ecore_Drm maintain keymaps about each keyboard devices. Test Plan: Connect a keyboard device and watch flow of ioctl. Originally Ecore_Drm opened xkb data and compile keymap, but after patch, that ioctl is disppeared. @feature Reviewers: raster, devilhorns, ManMower Reviewed By: devilhorns, ManMower Subscribers: cedric, input.hacker, ohduna, jpeg Differential Revision: https://phab.enlightenment.org/D3503
Diffstat (limited to 'src/lib/ecore_drm')
-rw-r--r--src/lib/ecore_drm/Ecore_Drm.h27
-rw-r--r--src/lib/ecore_drm/ecore_drm_device.c80
-rw-r--r--src/lib/ecore_drm/ecore_drm_evdev.c2
-rw-r--r--src/lib/ecore_drm/ecore_drm_private.h8
4 files changed, 114 insertions, 3 deletions
diff --git a/src/lib/ecore_drm/Ecore_Drm.h b/src/lib/ecore_drm/Ecore_Drm.h
index 1f110ef..5c50f10 100644
--- a/src/lib/ecore_drm/Ecore_Drm.h
+++ b/src/lib/ecore_drm/Ecore_Drm.h
@@ -6,6 +6,7 @@
6# include <drm_fourcc.h> 6# include <drm_fourcc.h>
7# include <Ecore.h> 7# include <Ecore.h>
8# include <Eeze.h> 8# include <Eeze.h>
9# include <xkbcommon/xkbcommon.h>
9 10
10# ifdef EAPI 11# ifdef EAPI
11# undef EAPI 12# undef EAPI
@@ -382,6 +383,32 @@ EAPI Eina_Bool ecore_drm_device_software_setup(Ecore_Drm_Device *dev);
382EAPI Eina_Bool ecore_drm_device_pointer_left_handed_set(Ecore_Drm_Device *dev, Eina_Bool left_handed); 383EAPI Eina_Bool ecore_drm_device_pointer_left_handed_set(Ecore_Drm_Device *dev, Eina_Bool left_handed);
383 384
384/** 385/**
386 * Setup a cached context to use same context for each devices
387 *
388 * This function will setup a cached context to use same context for each devices
389 * This function will be called before initialize Ecore_Drm.
390 *
391 * @param ctx struct xkb_context used in libxkbcommon
392 *
393 * @ingroup Ecore_Drm_Device_Group
394 * @since 1.17
395 */
396EAPI void ecore_drm_device_keyboard_cached_context_set(struct xkb_context *ctx);
397
398/**
399 * Setup a cached keymap to use same keymap for each devices
400 *
401 * This function will setup a cached keymap to use same keymap for each devices
402 * This function will be called before initialize Ecore_Drm.
403 *
404 * @param map struct xkb_keymap used in libxkbcommon
405 *
406 * @ingroup Ecore_Drm_Device_Group
407 * @since 1.17
408 */
409EAPI void ecore_drm_device_keyboard_cached_keymap_set(struct xkb_keymap *map);
410
411/**
385 * Find an Ecore_Drm_Output at the given coordinates 412 * Find an Ecore_Drm_Output at the given coordinates
386 * 413 *
387 * This function will loop all the existing outputs in Ecore_Drm_Device and 414 * This function will loop all the existing outputs in Ecore_Drm_Device and
diff --git a/src/lib/ecore_drm/ecore_drm_device.c b/src/lib/ecore_drm/ecore_drm_device.c
index f0c0cfe..d3eb91f 100644
--- a/src/lib/ecore_drm/ecore_drm_device.c
+++ b/src/lib/ecore_drm/ecore_drm_device.c
@@ -107,6 +107,58 @@ _ecore_drm_device_cb_output_event(const char *device EINA_UNUSED, Eeze_Udev_Even
107 _ecore_drm_outputs_update(dev); 107 _ecore_drm_outputs_update(dev);
108} 108}
109 109
110struct xkb_context *
111_ecore_drm_device_cached_context_get(enum xkb_context_flags flags)
112{
113 if (!cached_context)
114 return xkb_context_new(flags);
115 else
116 return xkb_context_ref(cached_context);
117}
118
119struct xkb_keymap *
120_ecore_drm_device_cached_keymap_get(struct xkb_context *ctx,
121 const struct xkb_rule_names *names,
122 enum xkb_keymap_compile_flags flags)
123{
124 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, NULL);
125
126 if (!cached_keymap)
127 return xkb_map_new_from_names(ctx, names, flags);
128 else
129 return xkb_map_ref(cached_keymap);
130}
131
132void
133_ecore_drm_device_cached_context_update(struct xkb_context *ctx)
134{
135 Eina_List *l;
136 Ecore_Drm_Device *dev;
137
138 EINA_LIST_FOREACH(drm_devices, l, dev)
139 {
140 xkb_context_unref(dev->xkb_ctx);
141 dev->xkb_ctx = xkb_context_ref(ctx);
142 }
143}
144
145void
146_ecore_drm_device_cached_keymap_update(struct xkb_keymap *map)
147{
148 Eina_List *l, *l2, *l3;
149 Ecore_Drm_Device *dev;
150 Ecore_Drm_Seat *seat;
151 Ecore_Drm_Evdev *edev;
152
153 EINA_LIST_FOREACH(drm_devices, l, dev)
154 EINA_LIST_FOREACH(dev->seats, l2, seat)
155 EINA_LIST_FOREACH(seat->devices, l3, edev)
156 {
157 xkb_keymap_unref(edev->xkb.keymap);
158 edev->xkb.keymap = xkb_keymap_ref(map);
159 }
160}
161
110/** 162/**
111 * @defgroup Ecore_Drm_Device_Group Device manipulation functions 163 * @defgroup Ecore_Drm_Device_Group Device manipulation functions
112 * 164 *
@@ -308,7 +360,7 @@ ecore_drm_device_open(Ecore_Drm_Device *dev)
308 } 360 }
309 361
310 /* try to create xkb context */ 362 /* try to create xkb context */
311 if (!(dev->xkb_ctx = xkb_context_new(0))) 363 if (!(dev->xkb_ctx = _ecore_drm_device_cached_context_get(0)))
312 { 364 {
313 ERR("Failed to create xkb context: %m"); 365 ERR("Failed to create xkb context: %m");
314 return EINA_FALSE; 366 return EINA_FALSE;
@@ -590,3 +642,29 @@ ecore_drm_device_pointer_left_handed_set(Ecore_Drm_Device *dev, Eina_Bool left_h
590 } 642 }
591 return EINA_TRUE; 643 return EINA_TRUE;
592} 644}
645
646EAPI void
647ecore_drm_device_keyboard_cached_context_set(struct xkb_context *ctx)
648{
649 EINA_SAFETY_ON_NULL_RETURN(ctx);
650
651 if (cached_context == ctx) return;
652
653 if (cached_context)
654 _ecore_drm_device_cached_context_update(ctx);
655
656 cached_context = ctx;
657}
658
659EAPI void
660ecore_drm_device_keyboard_cached_keymap_set(struct xkb_keymap *map)
661{
662 EINA_SAFETY_ON_NULL_RETURN(map);
663
664 if (cached_keymap == map) return;
665
666 if (cached_keymap)
667 _ecore_drm_device_cached_keymap_update(map);
668
669 cached_keymap = map;
670}
diff --git a/src/lib/ecore_drm/ecore_drm_evdev.c b/src/lib/ecore_drm/ecore_drm_evdev.c
index a57c7e8..1f21dd6 100644
--- a/src/lib/ecore_drm/ecore_drm_evdev.c
+++ b/src/lib/ecore_drm/ecore_drm_evdev.c
@@ -116,7 +116,7 @@ _device_keyboard_setup(Ecore_Drm_Evdev *edev)
116 if (!input->dev->xkb_ctx) return; 116 if (!input->dev->xkb_ctx) return;
117 117
118 /* create keymap from xkb context */ 118 /* create keymap from xkb context */
119 edev->xkb.keymap = xkb_map_new_from_names(input->dev->xkb_ctx, NULL, 0); 119 edev->xkb.keymap = _ecore_drm_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
120 if (!edev->xkb.keymap) 120 if (!edev->xkb.keymap)
121 { 121 {
122 ERR("Failed to create keymap: %m"); 122 ERR("Failed to create keymap: %m");
diff --git a/src/lib/ecore_drm/ecore_drm_private.h b/src/lib/ecore_drm/ecore_drm_private.h
index 6d30dee..c3ba84c 100644
--- a/src/lib/ecore_drm/ecore_drm_private.h
+++ b/src/lib/ecore_drm/ecore_drm_private.h
@@ -24,7 +24,6 @@
24# include <linux/major.h> 24# include <linux/major.h>
25# include <linux/input.h> 25# include <linux/input.h>
26# include <libinput.h> 26# include <libinput.h>
27# include <xkbcommon/xkbcommon.h>
28 27
29# ifdef HAVE_SYSTEMD 28# ifdef HAVE_SYSTEMD
30# include <systemd/sd-login.h> 29# include <systemd/sd-login.h>
@@ -69,6 +68,8 @@
69# endif 68# endif
70 69
71extern int _ecore_drm_log_dom; 70extern int _ecore_drm_log_dom;
71struct xkb_keymap *cached_keymap;
72struct xkb_context *cached_context;
72 73
73# define EVDEV_MAX_SLOTS 32 74# define EVDEV_MAX_SLOTS 32
74 75
@@ -294,4 +295,9 @@ Eina_Bool _ecore_drm_dbus_session_release(void);
294 295
295void _ecore_drm_inputs_init(void); 296void _ecore_drm_inputs_init(void);
296void _ecore_drm_inputs_shutdown(void); 297void _ecore_drm_inputs_shutdown(void);
298
299struct xkb_context *_ecore_drm_device_cached_context_get(enum xkb_context_flags flags);
300struct xkb_keymap *_ecore_drm_device_cached_keymap_get(struct xkb_context *ctx,
301 const struct xkb_rule_names *names,
302 enum xkb_keymap_compile_flags flags);
297#endif 303#endif