Re: XTestFakeKeyEvent GDK-equivalent

2018-07-09 Thread Anarchean via gtk-list
‐‐‐ Original Message ‐‐‐

On 5 July 2018 10:32 PM, Allin Cottrell  wrote:

> On Thu, 5 Jul 2018, Anarchean via gtk-list wrote:
> 
> > I'm working into implementing a virtual remote keyboard/touch pad
> > 
> > daemon for Linux, currently I'm dumping events into an uinput
> > 
> > device, but that is giving me some trouble with my keyboard layout
> > 
> > (which is brazillian, br-abnt2). I was looking for a way to this
> > 
> > in X, found XTestFakeKeyEvent and was wondering if I could make it
> > 
> > simpler and cross-platform using GDK3. I tried this attached code,
> > 
> > but it doesn't do anything. I was wondering if someone has done
> > 
> > this before and know what I'm doing wrong or if I should just give
> > 
> > up doing with GDK.
> 
> The context is a little different, but the attached function works,
> 
> given a pointers to an existing GtkWidget and GdkEvent.
> 

I tried your code out. It works OK, but its limited to emitting events to a GTK 
managed window and what I really wanted was to insert events into the 
X11/Wayland Display server, so that any application which has the focus could 
receive the events.

Maybe that is not possible within GTK and I need to access lower-level 
libraries like X/Wayland?

> > Also, this is an extra, if I can't just fake key events, what
> > 
> > should I use to map unicode chars into linux/input.h event key
> > 
> > codes based on my keyboard layout on X? What about Wayland?
> 
> man xmodmap ?
> 

I didn't know about xmodmap. I don't want to capture the standard out, tho. But 
I'll look into their source code to say what they code to capture the mapping.

Thank you for your help, Allin! That gave me some direction.

> 
> -
> 
> Allin Cottrell
> 
> Department of Economics
> 
> Wake Forest University


___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: XTestFakeKeyEvent GDK-equivalent

2018-07-07 Thread Anarchean via gtk-list
Hello Emmanuele,

Well, my requirements allow an only-X or -Wayland solution, but I totally 
understand what you mean, I feel it is weird using a testing API do implement 
functionality.
My current solution is using uniput to create a virtual device in user space, 
I'm just having trouble with the keyboard layout, GDK was my hope to convert 
char -> keysym and send it directly to the X server. I guess I'll just have to 
get the mapping right in both server and client, either manually or trying to 
read XKB mappings.
I'm looking at Onboard (https://code.launchpad.net/~onboard/onboard/trunk) code 
and I think they do what I want.

Anyway, thank you for the help.

Sent with [ProtonMail](https://protonmail.com) Secure Email.

‐‐‐ Original Message ‐‐‐
On 7 July 2018 9:51 AM, Emmanuele Bassi  wrote:

> Hi;
>
> virtual keyboards running outside of the windowing system platform as clients 
> do not use the XTest API — mostly because it's meant only for testing X, and 
> because it's only for X. Injecting synthetic events into the windowing system 
> is just not going to give you what you want, if what you want is to write a 
> input driver. Additionally, GDK won't let you do this because GDK is a client 
> toolkit, and it can only consume events coming from the windowing system, not 
> inject them for random clients to process.
>
> You will need to write a device driver — either for X11, or for the Linux 
> kernel — that does this for you.
>
> Ciao,
>  Emmanuele.
>
> On Fri, 6 Jul 2018 at 01:49, Anarchean via gtk-list  
> wrote:
>
>> Hi,
>>
>> I'm working into implementing a virtual remote keyboard/touch pad daemon for 
>> Linux, currently I'm dumping events into an uinput device, but that is 
>> giving me some trouble with my keyboard layout (which is brazillian, 
>> br-abnt2). I was looking for a way to this in X, found XTestFakeKeyEvent and 
>> was wondering if I could make it simpler and cross-platform using
>> GDK3. I tried this attached code, but it doesn't do anything. I was 
>> wondering if someone has done this before and know what I'm doing wrong or 
>> if I should just give up doing with GDK.
>>
>> Also, this is an extra, if I can't just fake key events, what should I use 
>> to map unicode chars into linux/input.h event key codes based on my keyboard 
>> layout on X? What about Wayland?
>>
>> Thank you!
>>
>> Sent with [ProtonMail](https://protonmail.com) Secure Email.
>>
>> ___
>> gtk-list mailing list
>> gtk-list@gnome.org
>> https://mail.gnome.org/mailman/listinfo/gtk-list
>
> --
> https://www.bassi.io
> [@] ebassi [@gmail.com]___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: XTestFakeKeyEvent GDK-equivalent

2018-07-07 Thread Anarchean via gtk-list
Hi James,

xdotool is a good option, but I would prefer to use a library instead, and a 
cross-platform one. I looked xdotool source code, and they use XTest 
internally. I was just curious to see if there were any way of doing that 
directly from GTK.

Anyway, thank you for answering.

‐‐‐ Original Message ‐‐‐

On 6 July 2018 6:30 PM, James Cameron  wrote:

> For quick hacks or testing apps, I use xdotool. I've no idea if it
> 
> works with Wayland though.
> 
> 
> --
> 
> James Cameron
> 
> http://quozl.netrek.org/
> 
> gtk-list mailing list
> 
> gtk-list@gnome.org
> 
> https://mail.gnome.org/mailman/listinfo/gtk-list


___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: XTestFakeKeyEvent GDK-equivalent

2018-07-07 Thread Emmanuele Bassi via gtk-list
Hi;

virtual keyboards running outside of the windowing system platform as
clients do not use the XTest API — mostly because it's meant only for
testing X, and because it's only for X. Injecting synthetic events into the
windowing system is just not going to give you what you want, if what you
want is to write a input driver. Additionally, GDK won't let you do this
because GDK is a client toolkit, and it can only consume events coming from
the windowing system, not inject them for random clients to process.

You will need to write a device driver — either for X11, or for the Linux
kernel — that does this for you.

Ciao,
 Emmanuele.

On Fri, 6 Jul 2018 at 01:49, Anarchean via gtk-list 
wrote:

> Hi,
>
> I'm working into implementing a virtual remote keyboard/touch pad daemon
> for Linux, currently I'm dumping events into an uinput device, but that is
> giving me some trouble with my keyboard layout (which is brazillian,
> br-abnt2). I was looking for a way to this in X, found XTestFakeKeyEvent
> and was wondering if I could make it simpler and cross-platform using
> GDK3. I tried this attached code, but it doesn't do anything. I was
> wondering if someone has done this before and know what I'm doing wrong or
> if I should just give up doing with GDK.
>
> Also, this is an extra, if I can't just fake key events, what should I use
> to map unicode chars into linux/input.h event key codes based on my
> keyboard layout on X? What about Wayland?
>
> Thank you!
>
>
> Sent with ProtonMail  Secure Email.
>
> ___
> gtk-list mailing list
> gtk-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-list
>


-- 
https://www.bassi.io
[@] ebassi [@gmail.com]
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: XTestFakeKeyEvent GDK-equivalent

2018-07-06 Thread James Cameron
For quick hacks or testing apps, I use xdotool.  I've no idea if it
works with Wayland though.

-- 
James Cameron
http://quozl.netrek.org/
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: XTestFakeKeyEvent GDK-equivalent

2018-07-06 Thread Allin Cottrell

On Fri, 6 Jul 2018, Anarchean wrote:


On 5 July 2018 10:32 PM, Allin Cottrell  wrote:

[...]

The context is a little different, but the attached function works,
given pointers to an existing GtkWidget and GdkEvent.


I tried your code out. It works OK, but its limited to emitting 
events to a GTK managed window and what I really wanted was to 
insert events into the X11/Wayland Display server, so that any 
application which has the focus could receive the events.


Maybe that is not possible within GTK and I need to access 
lower-level libraries like X/Wayland?


Yes, I expect so. It occurred to me after posting my variant code 
that it would not do what you wanted, if you're looking to send 
keystrokes to some arbitrary target outside of your GTK application.
It seems pretty clear that if you want to send to an arbitrary X11 
(or Wayland) window you'd need an API that gives you an ID for that 
window, at least.


--
Allin Cottrell
Department of Economics
Wake Forest University
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: XTestFakeKeyEvent GDK-equivalent

2018-07-06 Thread Anarchean via gtk-list



​Sent with ProtonMail Secure Email.​

‐‐‐ Original Message ‐‐‐

On 6 July 2018 9:57 AM, Eric Williams  wrote:

> Hello,
> 
> On 07/05/2018 02:40 PM, Anarchean via gtk-list wrote:
> 
> > Hi,
> > 
> > I'm working into implementing a virtual remote keyboard/touch pad daemon
> > 
> > for Linux, currently I'm dumping events into an uinput device, but that
> > 
> > is giving me some trouble with my keyboard layout (which is brazillian,
> > 
> > br-abnt2). I was looking for a way to this in X, found XTestFakeKeyEvent
> > 
> > and was wondering if I could make it simpler and cross-platform using
> > 
> > GDK3. I tried this attached code, but it doesn't do anything. I was
> > 
> > wondering if someone has done this before and know what I'm doing wrong
> > 
> > or if I should just give up doing with GDK.
> 
> Perhaps something like this?
> 
> https://developer.gnome.org/gdk3/stable/gdk3-Testing.html#gdk-test-simulate-key
> 
> 
> -
> 
> Eric Williams
> 
> Software Engineer - Eclipse/SWT Team
> 
> Red Hat

Hey, Eric. I've just tried that function, it didn't do anything, I'm attaching 
my code so you can see if I'm doing this wrong.
#include 
#include 
#include 

GdkWindow* gSuperWindow;

static gboolean
press_key (gpointer data)
{
  GdkWindow *window;
  GdkModifierType NO_MODIFIER = (GdkModifierType) 0;
  int* c = (int *) data;

  window = gdk_get_default_root_window();

  gdk_test_simulate_key (gSuperWindow, -1, -1, GDK_KEY_a, NO_MODIFIER,
			 GDK_KEY_PRESS);
  gdk_test_simulate_key (gSuperWindow, -1, -1, GDK_KEY_a, NO_MODIFIER,
			 GDK_KEY_RELEASE);

  (*c)++;

  printf("Char printed\n");

  if (*c < 10) {
return TRUE;
  } else {
return FALSE;
  }
}


static void
activate (GApplication* app)
{
  GtkWidget* window;
  GtkWidget* text;
  
  window = gtk_application_window_new (GTK_APPLICATION (app));
  text = gtk_entry_new ();

  gtk_container_add (GTK_CONTAINER (window), text);
  
  gtk_widget_show_all (window);

  gSuperWindow = gtk_widget_get_window (window);
  
  g_timeout_add (500, press_key, new int {0});
}


int main(int argc, char** argv)
{
  GtkApplication* app;
  int status;
  
  app = gtk_application_new ("linuxrc.eric", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), app);

  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);
  
  return status;
}
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: XTestFakeKeyEvent GDK-equivalent

2018-07-06 Thread Eric Williams via gtk-list

Hello,

On 07/05/2018 02:40 PM, Anarchean via gtk-list wrote:

Hi,

I'm working into implementing a virtual remote keyboard/touch pad daemon 
for Linux, currently I'm dumping events into an uinput device, but that 
is giving me some trouble with my keyboard layout (which is brazillian, 
br-abnt2). I was looking for a way to this in X, found XTestFakeKeyEvent 
and was wondering if I could make it simpler and cross-platform using
GDK3. I tried this attached code, but it doesn't do anything. I was 
wondering if someone has done this before and know what I'm doing wrong 
or if I should just give up doing with GDK.


Perhaps something like this? 
https://developer.gnome.org/gdk3/stable/gdk3-Testing.html#gdk-test-simulate-key



--
Eric Williams
Software Engineer - Eclipse/SWT Team
Red Hat
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: XTestFakeKeyEvent GDK-equivalent

2018-07-05 Thread Allin Cottrell

On Thu, 5 Jul 2018, Anarchean via gtk-list wrote:

I'm working into implementing a virtual remote keyboard/touch pad 
daemon for Linux, currently I'm dumping events into an uinput 
device, but that is giving me some trouble with my keyboard layout 
(which is brazillian, br-abnt2). I was looking for a way to this 
in X, found XTestFakeKeyEvent and was wondering if I could make it 
simpler and cross-platform using GDK3. I tried this attached code, 
but it doesn't do anything. I was wondering if someone has done 
this before and know what I'm doing wrong or if I should just give 
up doing with GDK.


The context is a little different, but the attached function works, 
given a pointers to an existing GtkWidget and GdkEvent.


Also, this is an extra, if I can't just fake key events, what 
should I use to map unicode chars into linux/input.h event key 
codes based on my keyboard layout on X? What about Wayland?


man xmodmap ?

--
Allin Cottrell
Department of Economics
Wake Forest Universitystatic void manufacture_keystroke (GtkWidget *widget,
   GdkEvent *orig,
   guint uval)
{
GdkKeymap *keymap = NULL;
GdkKeymapKey *keys;
gint n_keys;

#if GTK_MAJOR_VERSION >= 3 || defined(G_OS_WIN32)
/* with GDK 3, we can't pass NULL for keymap below -- and neither
   (it appears) for GDK 2 on MS Windows
*/
keymap = gdk_keymap_get_for_display(gdk_display_get_default());
#endif

if (gdk_keymap_get_entries_for_keyval(keymap, uval, , _keys)) {
guint16 hardware_keycode;
GdkEvent *event;

hardware_keycode = keys[0].keycode;
g_free(keys);

event = gdk_event_new(GDK_KEY_PRESS);
event->key.window = g_object_ref(gtk_widget_get_window(widget));
event->key.hardware_keycode = hardware_keycode;
event->key.keyval = gdk_unicode_to_keyval(uval);
event->key.length = 1;
event->key.send_event = FALSE;
event->key.time = GDK_CURRENT_TIME;

#if GTK_MAJOR_VERSION >= 3
/* we get warning spew if no device is attached */
gdk_event_set_device(event, gdk_event_get_device(orig));
#endif

gtk_main_do_event(event);
gdk_event_free(event);
}
}
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


XTestFakeKeyEvent GDK-equivalent

2018-07-05 Thread Anarchean via gtk-list
Hi,

I'm working into implementing a virtual remote keyboard/touch pad daemon for 
Linux, currently I'm dumping events into an uinput device, but that is giving 
me some trouble with my keyboard layout (which is brazillian, br-abnt2). I was 
looking for a way to this in X, found XTestFakeKeyEvent and was wondering if I 
could make it simpler and cross-platform using
GDK3. I tried this attached code, but it doesn't do anything. I was wondering 
if someone has done this before and know what I'm doing wrong or if I should 
just give up doing with GDK.

Also, this is an extra, if I can't just fake key events, what should I use to 
map unicode chars into linux/input.h event key codes based on my keyboard 
layout on X? What about Wayland?

Thank you!

Sent with [ProtonMail](https://protonmail.com) Secure Email.#include 
#include 
#include 
#include 
#include 
#include 

static void
activate (GApplication *app)
{
  GdkEventKey event;
  GdkDisplay *dpy;
  GdkKeymap *kmap;
  GdkKeymapKey *keys;
  gint n_keys;
  guint keyval = GDK_KEY_o;

  dpy = gdk_display_get_default ();
  kmap = gdk_keymap_get_for_display (dpy);

  gdk_keymap_get_entries_for_keyval (kmap, keyval, , _keys);

  memset (, 0, sizeof (event));
  event.type = GDK_KEY_PRESS;
  event.window = NULL;
  event.send_event = 0;

  event.time = GDK_CURRENT_TIME;
  event.state = 0;
  event.keyval = keyval;
  event.length = 1;
  event.string = strdup ("o");
  event.hardware_keycode = keys->keycode;
  event.group = keys->group;
  event.is_modifier = 0;

  gdk_display_put_event (dpy, (GdkEvent *) ());
  event.type = GDK_KEY_RELEASE;

  gdk_display_put_event (dpy, (GdkEvent *) ());

  while (gtk_events_pending ()) {
gtk_main_iteration ();
  }
}

int
main (int argc, char **argv)
{
  GtkApplication *app;
  app = gtk_application_new ("com.anarchean.linuxrc", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  
  return g_application_run (G_APPLICATION (app), argc, argv);
}
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list