Navigation Menu

Skip to content

Commit

Permalink
ximagesink, xvimagesink: don't use XkbKeycodeToKeysym if Xkb is unava…
Browse files Browse the repository at this point in the history
…ilable

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.
  • Loading branch information
mita authored and GStreamer Merge Bot committed Nov 19, 2019
1 parent fd83086 commit 2d65683
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 6 deletions.
8 changes: 7 additions & 1 deletion sys/ximage/meson.build
@@ -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,
Expand Down
19 changes: 17 additions & 2 deletions sys/ximage/ximagesink.c
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions sys/ximage/ximagesink.h
Expand Up @@ -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
Expand All @@ -107,6 +109,7 @@ struct _GstXContext
GValue *par; /* calculated pixel aspect ratio */

gboolean use_xshm;
gboolean use_xkb;

GstCaps *caps;
GstCaps *last_caps;
Expand Down
8 changes: 7 additions & 1 deletion sys/xvimage/meson.build
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions sys/xvimage/xvcontext.c
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions sys/xvimage/xvcontext.h
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions sys/xvimage/xvimagesink.c
Expand Up @@ -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 {
Expand Down

0 comments on commit 2d65683

Please sign in to comment.