ximagesink, xvimagesink: don't use XkbKeycodeToKeysym if Xkb is unavailable
authorAkinobu Mita <akinobu.mita@gmail.com>
Tue, 21 May 2019 12:59:23 +0000 (21:59 +0900)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 19 Nov 2019 14:28:35 +0000 (14:28 +0000)
ximagesink and xvimagesink use XkbKeycodeToKeysym when the key event is
received. However, this function returns NoSymbol if Xkb is unavailable.

This causes all key events to be translated to "unknown" key when running
ximagsink under some VNC.

Fix it by using XKeycodeToKeysym if Xkb is unavailable.

sys/ximage/meson.build
sys/ximage/ximagesink.c
sys/ximage/ximagesink.h
sys/xvimage/meson.build
sys/xvimage/xvcontext.c
sys/xvimage/xvcontext.h
sys/xvimage/xvimagesink.c

index f01bc20..c2ce795 100644 (file)
@@ -1,6 +1,12 @@
+no_warn_args = []
+# XKeycodeToKeysym is deprecated, but we use it when Xkb is unavailable
+if cc.has_argument ('-Wno-deprecated-declarations')
+  no_warn_args += '-Wno-deprecated-declarations'
+endif
+
 gstximage = library('gstximagesink',
   'ximagesink.c', 'ximage.c', 'ximagepool.c',
-  c_args : gst_plugins_base_args,
+  c_args : gst_plugins_base_args + no_warn_args,
   include_directories: [configinc, libsinc],
   dependencies : glib_deps + [video_dep, gst_base_dep, gst_dep, x11_dep, xshm_dep],
   install : true,
index 2881acb..36e678d 100644 (file)
@@ -631,8 +631,13 @@ gst_x_image_sink_handle_xevents (GstXImageSink * ximagesink)
         /* Key pressed/released over our window. We send upstream
            events for interactivity/navigation */
         g_mutex_lock (&ximagesink->x_lock);
-        keysym = XkbKeycodeToKeysym (ximagesink->xcontext->disp,
-            e.xkey.keycode, 0, 0);
+        if (ximagesink->xcontext->use_xkb) {
+          keysym = XkbKeycodeToKeysym (ximagesink->xcontext->disp,
+              e.xkey.keycode, 0, 0);
+        } else {
+          keysym = XKeycodeToKeysym (ximagesink->xcontext->disp,
+              e.xkey.keycode, 0);
+        }
         if (keysym != NoSymbol) {
           key_str = XKeysymToString (keysym);
         } else {
@@ -844,6 +849,9 @@ gst_x_image_sink_xcontext_get (GstXImageSink * ximagesink)
   gint endianness;
   GstVideoFormat vformat;
   guint32 alpha_mask;
+  int opcode, event, err;
+  int major = XkbMajorVersion;
+  int minor = XkbMinorVersion;
 
   g_return_val_if_fail (GST_IS_X_IMAGE_SINK (ximagesink), NULL);
 
@@ -915,6 +923,13 @@ gst_x_image_sink_xcontext_get (GstXImageSink * ximagesink)
     xcontext->use_xshm = FALSE;
     GST_DEBUG ("ximagesink is not using XShm extension");
   }
+  if (XkbQueryExtension (xcontext->disp, &opcode, &event, &err, &major, &minor)) {
+    xcontext->use_xkb = TRUE;
+    GST_DEBUG ("ximagesink is using Xkb extension");
+  } else {
+    xcontext->use_xkb = FALSE;
+    GST_DEBUG ("ximagesink is not using Xkb extension");
+  }
 
   /* extrapolate alpha mask */
   if (xcontext->depth == 32) {
index 1f29050..8574ef3 100644 (file)
@@ -81,6 +81,8 @@ typedef struct _GstXImageSinkClass GstXImageSinkClass;
  * @heightmm ratio
  * @use_xshm: used to known whether of not XShm extension is usable or not even
  * if the Extension is present
+ * @use_xkb: used to known wether of not Xkb extension is usable or not even
+ * if the Extension is present
  * @caps: the #GstCaps that Display @disp can accept
  *
  * Structure used to store various information collected/calculated for a
@@ -107,6 +109,7 @@ struct _GstXContext
   GValue *par;                  /* calculated pixel aspect ratio */
 
   gboolean use_xshm;
+  gboolean use_xkb;
 
   GstCaps *caps;
   GstCaps *last_caps;
index 17a736a..b8b8f00 100644 (file)
@@ -6,13 +6,19 @@ xvimage_sources = [
   'xvimagesink.c',
 ]
 
+no_warn_args = []
+# XKeycodeToKeysym is deprecated, but we use it when Xkb is unavailable
+if cc.has_argument ('-Wno-deprecated-declarations')
+  no_warn_args += '-Wno-deprecated-declarations'
+endif
+
 xvideo_dep = dependency('xv', required : get_option('xvideo'))
 core_conf.set('HAVE_XVIDEO', x11_dep.found() and xvideo_dep.found())
 
 if xvideo_dep.found()
   gstxvimage = library('gstxvimagesink',
     xvimage_sources,
-    c_args : gst_plugins_base_args,
+    c_args : gst_plugins_base_args + no_warn_args,
     include_directories: [configinc, libsinc],
     dependencies : glib_deps + [video_dep, gst_base_dep, gst_dep, x11_dep, xshm_dep, xvideo_dep, libm],
     install : true,
index ec87cc8..7b2cc44 100644 (file)
@@ -636,6 +636,9 @@ gst_xvcontext_new (GstXvContextConfig * config, GError ** error)
   const char *channels[4] = { "XV_HUE", "XV_SATURATION",
     "XV_BRIGHTNESS", "XV_CONTRAST"
   };
+  int opcode, event, err;
+  int major = XkbMajorVersion;
+  int minor = XkbMinorVersion;
 
   g_return_val_if_fail (config != NULL, NULL);
 
@@ -718,6 +721,13 @@ gst_xvcontext_new (GstXvContextConfig * config, GError ** error)
     context->use_xshm = FALSE;
     GST_DEBUG ("xvimagesink is not using XShm extension");
   }
+  if (XkbQueryExtension (context->disp, &opcode, &event, &err, &major, &minor)) {
+    context->use_xkb = TRUE;
+    GST_DEBUG ("xvimagesink is using Xkb extension");
+  } else {
+    context->use_xkb = FALSE;
+    GST_DEBUG ("xvimagesink is not using Xkb extension");
+  }
 
   xv_attr = XvQueryPortAttributes (context->disp, context->xv_port_id, &N_attr);
 
index 8388668..4efe3f0 100644 (file)
@@ -110,6 +110,8 @@ struct _GstXvImageFormat
  * @heightmm ratio
  * @use_xshm: used to known whether of not XShm extension is usable or not even
  * if the Extension is present
+ * @use_xkb: used to known wether of not Xkb extension is usable or not even
+ * if the Extension is present
  * @xv_port_id: the XVideo port ID
  * @im_format: used to store at least a valid format for XShm calls checks
  * @formats_list: list of supported image formats on @xv_port_id
@@ -145,6 +147,7 @@ struct _GstXvContext
   GValue *par;                  /* calculated pixel aspect ratio */
 
   gboolean use_xshm;
+  gboolean use_xkb;
 
   XvPortID xv_port_id;
   guint nb_adaptors;
index 50d9dd2..babf515 100644 (file)
@@ -485,8 +485,13 @@ gst_xv_image_sink_handle_xevents (GstXvImageSink * xvimagesink)
         /* Key pressed/released over our window. We send upstream
            events for interactivity/navigation */
         g_mutex_lock (&xvimagesink->context->lock);
-        keysym = XkbKeycodeToKeysym (xvimagesink->context->disp,
-            e.xkey.keycode, 0, 0);
+        if (xvimagesink->context->use_xkb) {
+          keysym = XkbKeycodeToKeysym (xvimagesink->context->disp,
+              e.xkey.keycode, 0, 0);
+        } else {
+          keysym = XKeycodeToKeysym (xvimagesink->context->disp,
+              e.xkey.keycode, 0);
+        }
         if (keysym != NoSymbol) {
           key_str = XKeysymToString (keysym);
         } else {