About Store Forum Documentation Contact



Post Reply 
Linux keyboard issues
Author Message
yvanvds Offline
Member

Post: #1
Linux keyboard issues
Hey

I'm doing some work with the linux version and came across some issues:

- My delete key does delete a character, but also puts a ? in place. Backspace works fine, but it's a bit annoying.
- Quotes don't seem to work. Single quotes as well as double ones. I am using a US International keyboard layout with dead keys.

I am also trying to log to the console window, which could be handy for a linux server program. Tried with LogConsole(true) but that doesn't do anything. Should this be working on linux or is it not yet implemented?

Cheers, and happy newyear!

yvan
01-01-2014 11:35 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Linux keyboard issues
Hi Yvan!

Delete Key:
could you start this app on your Linux, press the delete key, and attach the screen of the result?
Code:
/******************************************************************************/
TextLine tl;
/******************************************************************************/
void InitPre()
{
   EE_INIT();
   App.flag|=APP_MAXIMIZABLE;
}
bool Init()
{
   Gui+=tl.create(Rect_C(0, 0, 1, 0.1));
   return true;
}
void Shut()
{
}
bool Update()
{
   Gui.update();
   return true;
}
void Draw()
{
   D.clear(WHITE);
   Gui.draw();
   Str s; FREPA(tl())s+=S+(int)tl()[i]+", ";
   D.text(0, 0.5, s);
}
/******************************************************************************/
it will display the INT value of the extra character.
Then I can adjust the engine to ignore processing that character.
(Note: on Ubuntu 13.10 I don't have this issue)

Quotes:
I've just tried it and it works fine.
This is how I'm processing the key input:
init:
Code:
if(IM=XOpenIM(XDisplay, NULL, (char*)class_name, (char*)class_name))
      IC=XCreateIC(IM, XNClientWindow, hwnd, XNFocusWindow, hwnd, XNInputStyle, XIMPreeditNothing|XIMStatusNothing, XNResourceName, class_name, XNResourceClass, class_name, __null);

message loop:
Code:
case KeyPress:
         {
            KeyCode code=0;
            if(IC)
            {
               wchar_t chr[256];
               KeySym  symbol=0;
               int     status;
               int     pressed=XwcLookupString(IC, &event.xkey, chr, ELMS(chr), &symbol, &status);
                       code   =XKeysymToKeycode(XDisplay, symbol);
               FREP(pressed)Kb.putToBuffer(chr[i]);
            }else
            {
               char           chr[256];
               KeySym         symbol=0;
               XComposeStatus status;
               int            pressed=XLookupString(&event.xkey, chr, ELMS(chr), &symbol, &status);
                              code   =XKeysymToKeycode(XDisplay, symbol);
               FREP(pressed)Kb.putToBuffer(chr[i]);
            }

LogConsole:
this is currently supported only on Windows
01-03-2014 11:04 PM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Member

Post: #3
RE: Linux keyboard issues
Thanks. It is a bit late now in this part of the world, but i'll try tomorrow. Meanwhile, could you tell me what keyboard layout you are using? Assuming it is some form of qwerty, that might help too. I am also using ubuntu 13.10.

Regards,

yvan
01-03-2014 11:46 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Linux keyboard issues
When I click on the top right "En" element on the main menu in Linux, it says "English (US)" smile The same when in "System Settings" app in the keyboard section.

Tried it with both laptop keyboard, and external keyboard.

Also make sure your system doesn't have any shortcuts assigned to those keys (then the system could process that as macros and not forward the keys to the application)
01-03-2014 11:56 PM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Member

Post: #5
RE: Linux keyboard issues
Hi again.

The quotes problem is gone when i pick English (US) instead of English (US with dead keys). I think i'll manage with that.

The delete key problem does not happen in an app, it seems. If I type a few chars in the app you provided i can see their ascii code, and when i pres delete, the they just dissapear. So that works as expected. I'd send you a screen, but there's nothing to see. In the editor the problem is still there, even after changing my keyboard layout.

Another thing I just discovered: if I add an application called 'test', make gets in a neverending loop. It just keeps on compiling the same source smile No big deal, but since test is a pretty common name to use if you're just checking out something, it might confuse other users.
01-04-2014 07:25 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: Linux keyboard issues
Ok, I've found the DEL issue, I'll fix it for next release.

"test" app name is also fixed

this is a sample raw C++ code to be put straight into an empty NetBeans project
Code:
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xresource.h>
#include <X11/Xlocale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char ** argv)
{
    int screen_num, width, height;
    unsigned long background, border;
    Window win;
    XEvent ev;
    Display *dpy;
    XIM im;
    XIC ic;
    char *failed_arg;
    XIMStyles *styles;
    XIMStyle xim_requested_style;

    /* First connect to the display server, as specified in the DISPLAY
    environment variable. */
    if (setlocale(LC_ALL, "") == NULL) {
        return 9;
    }

    if (!XSupportsLocale()) {
        return 10;
    }
    if (XSetLocaleModifiers("") == NULL) {
        return 11;
    }

    dpy = XOpenDisplay(NULL);
    if (!dpy) {
        fprintf(stderr, "unable to connect to display");
        return 7;
    }
    /* these are macros that pull useful data out of the display object */
    /* we use these bits of info enough to want them in their own variables */
    screen_num = DefaultScreen(dpy);
    background = BlackPixel(dpy, screen_num);
    border = WhitePixel(dpy, screen_num);

    width = 400; /* start with a small window */
    height = 200;

    win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), /* display, parent */
        0,0, /* x, y: the window manager will place the window elsewhere */
        width, height, /* width, height */
        2, border, /* border width & colour, unless you have a window manager */
        background); /* background colour */

    /* tell the display server what kind of events we would like to see */
    XSelectInput(dpy, win, ButtonPressMask|StructureNotifyMask|KeyPressMask|KeyReleaseMask|KeymapStateMask)​;

    /* okay, put the window on the screen, please */
    XMapWindow(dpy, win);

    im = XOpenIM(dpy, NULL, NULL, NULL);
    if (im == NULL) {
        fputs("Could not open input method\n", stdout);
        return 2;
    }

    failed_arg = XGetIMValues(im, XNQueryInputStyle, &styles, NULL);

    if (failed_arg != NULL) {
      fputs("XIM Can't get styles\n", stdout);
      return 3;
    }

    int i;
    for (i = 0; i < styles->count_styles; i++) {
        printf("style %d\n", styles->supported_styles[i]);
    }
    ic = XCreateIC(im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
    if (ic == NULL) {
        printf("Could not open IC\n");
        return 4;
    }

    XSetICFocus(ic);

    /* as each event that we asked about occurs, we respond.  In this
     * case we note if the window's shape changed, and exit if a button
     * is pressed inside the window */
    while(1) {
        XNextEvent(dpy, &ev);

        if (XFilterEvent(&ev, win))continue;

        switch(ev.type){
        case KeymapNotify:
            XRefreshKeyboardMapping(&ev.xmapping);
            break;
        case KeyPress:
            {
                int count = 0;
                KeySym keysym = 0;
                char buf[20];
                Status status = 0;
                count = Xutf8LookupString(ic, (XKeyPressedEvent*)&ev, buf, 20, &keysym, &status);

                printf("count: %d\n", count);
                if (status==XBufferOverflow)
                    printf("BufferOverflow\n");

                if (count)
                    printf("buffer: %s\n", buf);

                if (status == XLookupKeySym || status == XLookupBoth) {
                    printf("status: %d\n", status);
                }
                printf("pressed KEY: %d\n", keysym);
            }
            break;
        case KeyRelease:
            {
                int count = 0;
                KeySym keysym = 0;
                char buf[20];
                Status status = 0;
                count = XLookupString((XKeyEvent*)&ev, buf, 20, &keysym, NULL);

                if (count)
                    printf("in release buffer: %s\n", buf);

                printf("released KEY: %d\n", keysym);
            }
            break;
        case ConfigureNotify:
            if (width != ev.xconfigure.width
                    || height != ev.xconfigure.height) {
                width = ev.xconfigure.width;
                height = ev.xconfigure.height;
                printf("Size changed to: %d by %d", width, height);
            }
            break;
        case ButtonPress:
            XCloseDisplay(dpy);
            return 0;
        }
        fflush(stdout);
    }
}
I've been testing it and trying to modify, to make dead keys work and produce accented characters but can't.
01-05-2014 01:14 AM
Find all posts by this user Quote this message in a reply
Post Reply