Tk Source Code

View Ticket
Login
Ticket UUID: 3551802
Title: Use the Xkb API to simplify Tk's keyboard event handling
Type: RFE Version: None
Submitter: stwo Created on: 2012-07-30 05:00:28
Subsystem: 32. Key Symbols Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2020-03-12 10:31:19
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2020-03-12 10:31:19
Description:
Building Tk 8.5.12 results in a handful of compiler warnings stating that XKeycodeToKeysym is deprecated, all in unix/tkUnixKey.c.
Here's a naive patch that passes the tests.
I have no idea what is the correct thing to do here.
User Comments: jan.nijtmans added on 2020-03-12 10:31:05:
Fixed now in core-8-6-branch (by simply disable the deprecation warning) and trunk (by not using XKeycodeToKeysym () any more.

This means that Tk starting with version 8.7 needs X11 >= R6. I don't think that's a problem, but it should be in the release notes!

Thanks!

fvogel added on 2020-02-23 15:16:46:

Thank you so much for your answer Biran.

I have now removed the code that triggered the deprecation warning during the build. See [e44fc1ef]. This fixes the original report. If nobody objects I will merge this in a few days from now.

Regarding the broader goal of this ticket, which surfaced during the discussion below (i.e. "Use the Xkb API to simplify Tk's keyboard event handling"), it is not on my <TODO> list at the moment.


griffin added on 2020-02-05 22:42:45:
I don't recall the conditions that lead to the initial bug report.  I could not find any history in my archives either.  If I where to speculate, I would say it was due to some legacy Unix system or old remote display software.  I don't believe any of those exist anymore in our environ.  

I agree that it's time to pull the plug on this deprecated API.

fvogel added on 2020-02-05 21:34:34:

> Unfortunately, we don't know what triggered that bug.

True. I have pinged Brian (the OP of bug [3607830fff]) for details.

> Considering that (a) XKeycodeToKeysym is deprecated,
> (b) most all X11 are R6+ now, it's probably safe to remove.
>  Is 8+ years after deprecation enough?  Or should more time be given?

To mitigate this issue we could do this change in 8.7 only. I'm unsure about whether a TIP is needed or not (TCT members, please advise!).


bll added on 2020-02-05 20:04:51:
No, thanks for the explanation.
I skipped over seeing the bug link somehow.
Unfortunately, we don't know what triggered that bug.

Considering that (a) XKeycodeToKeysym is deprecated, (b) most all X11 are R6+
now, it's probably safe to remove.  Is 8+ years after deprecation enough?  Or
should more time be given?

I tried a search:
   site:github.com XkeycodeToKeysym
and it doesn't look like it is in wide use.

I would suspect that the bug was triggered by improper installs/configurations,
and can be safely ignored.

fvogel added on 2020-02-05 19:36:21:

Yeah, I had already mentioned bug [3607830fff] and I thought I had explained what was that bug and what was the corresponding fix all about. Either I'm mistaking, or I must have been misunderstood otherwise you wouldn't suggest what you just suggested. Let's try again.

Bug [3607830fff] discovered that, even if Xkb was detected as being present *at configure time*, it was possible that it was NOT available *at run time*. So the fix for this bug was to add a check executed at runtime. This check is based on the return result of XkbOpenDisplay (in TkpOpenDisplay) and sets a flag (TK_DISPLAY_USE_X) if Xkb is operational at runtime. Then, still at execution time, the TkKeycodeToKeysym macro makes use of this flag to call either XkbKeycodeToKeysym or XKeycodeToKeysym as a last resort when Xkb is not prsent. This is implemented in [a2433152], please have a look.

See also bgriffin's comment on 2013-03-14 21:27:54 in bug [3607830fff].

Note that TkKeycodeToKeysym is a #define, meaning that XKeycodeToKeysym finally still shows up in the source code everywhere TkKeycodeToKeysym is replaced by its expression by the compiler preprocessor. And this showing up triggers the warnings.

My point was that this is a runtime thing that may call XKeycodeToKeysym as a last resort option, and this call must not be wrapped in a #ifdef HAVE_XKBKEYCODETOKEYSYM because that would not cover the case of bug [3607830fff], which is "Xkb present at configure/build time but not available at run time".

So IMO the only way to remove the warnings is to break compatibility with old x11 having no support for Xkb.

On the other hand, if I misunderstood you please show me your patch proposal?


bll added on 2020-02-04 21:16:24:
You could wrap it in a

#ifdef HAVE_XKBKEYCODETOKEYSYM

and split the macro into two separate definitions.
But see also: Bug [3607830] (whereever that is).

fvogel added on 2020-02-04 20:43:49:

Since [addedfa6] we now have added this dependency on Xkb. This got later refined in [a2433152] by adding runtime checks that Xkb is available in the X server before attempting to use it. This was a fix for bug [3607830fff].

As Brian Griffin noted in that ticket, this fix does not prevent deprecation warnings to show up at build time, because of the following #define in unix/tkUnixKey.c:

#define TkKeycodeToKeysym(D,K,G,L)		\
    ((D)->flags & TK_DISPLAY_USE_XKB) ?		\
      XkbKeycodeToKeysym((D)->display,K,G,L) :	\
      XKeycodeToKeysym((D)->display,K,L)

I don't see any way of avoiding the deprecation warning.


dkf added on 2012-08-01 02:45:07:

allow_comments - 0

dkf added on 2012-08-01 02:44:05:

data_type - 362997

Be my guest, but this probably ought to be tracked as a FRQ. Converting

jenglish added on 2012-08-01 00:12:35:
... also, from a quick scan of the xkblib manual, if we're going to take a dependency on Xkb (limiting Tk to X11R6.1 and higher, BTW), it looks like a lot of the current adhoccery can be greatly simplified; Xkb has built-in support for much of what Tk does "by hand" now.

jenglish added on 2012-08-01 00:06:28:
> but the documentation is *terrible*
> and the patches to other code out there are no better.
> (So, situation normal for X11 API functions.)

This looks fairly comprehensive: http://www.x.org/wiki/XKB
(first hit when googling "Xkb").

See in particular:
http://www.x.org/releases/current/doc/libX11/XKB/xkblib.html

dkf added on 2012-07-31 21:48:53:

allow_comments - 1

Because the Xkb API appears to be implemented in libX11, I've not added any extra ifdeffery. Code might still not be correct, but we've little hope of correcting it.

dkf added on 2012-07-30 17:26:48:
The availability of the API looks good, and the header is the correct one.

What's not clear is whether setting the group parameter to 0 is always correct; I suspect it isn't, but the documentation is *terrible* and the patches to other code out there are no better. (So, situation normal for X11 API functions.)

stwo added on 2012-07-30 12:00:29:

File Added - 450114: patch-unix_tkUnixKey_c

Attachments: