Hi everybody,

I've attached bindings for the XTest extension (aka libxtst) and a small
demonstration program which will start/pause your music player.

This is how it should work:

        $ valac --pkg=x11 --pkg=xtst --vapidir=. Test.vala && ./Test 
        sizeof(char) = 1, sizeof(int) = 4, sizeof(long) = 4
        sizeof(X.KeyCode) = 1, sizeof(X.KeySym) = 4, sizeof(X.ID) = 4
        Display :0.0 opened
        String XF86AudioPlay has keysym 0x1008FF14
        Keysym 0x1008FF14 has keycode 172
        Keycode 172 pressed
        Keycode 172 released
        Display :0.0 flushed
        $

Please note that this patch needs the patch I submitted earlier[1].

I'm looking forward to any comments/criticism/whatever! If everything is
ok, I would be happy if you could merge this into master.

Best regards

Alexander Kurtz

[1] http://mail.gnome.org/archives/vala-list/2011-April/msg00036.html
/* xtst.vapi
 *
 * Copyright (C) 2011  Alexander Kurtz
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Alexander Kurtz <[email protected]>
 */


[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "X11/extensions/XTest.h")]
namespace X {
	class Test {
		[CCode (cname = "XTestQueryExtension")]
		public static bool query_extension(Display display, out int event_base_return, out int error_base_return, out int major_version_return, out int minor_version_return);

		[CCode (cname = "XTestCompareCursorWithWindow")]
		public static bool compare_cursor_with_window(Display display, Window window, Cursor cursor);

		[CCode (cname = "XTestCompareCurrentCursorWithWindow")]
		public static bool compare_current_cursor_with_window(Display display, Window window);

		[CCode (cname = "XTestFakeKeyEvent")]
		public static int fake_key_event(Display display, uint keycode, bool is_press, ulong delay);

		[CCode (cname = "XTestFakeButtonEvent")]
		public static int fake_button_event(Display display, uint button, bool is_press, ulong delay);

		[CCode (cname = "XTestFakeMotionEvent")]
		public static int fake_motion_event(Display display, int screen_number, int x, int y, ulong delay);
	
		[CCode (cname = "XTestFakeRelativeMotionEvent")]
		public static int fake_relative_motion_event(Display display, int screen_number, int x, int y, ulong delay);

		[CCode (cname = "XTestGrabControl")]
		public static int grab_control(Display display, bool impervious);

		[CCode (cname = "XTestSetGContextOfGC")]
		public static void set_g_context_of_gc(GC gc, GContext gid);

		[CCode (cname = "XTestSetVisualIDOfVisual")]
		public static void set_visual_id_of_visual(Visual visual, VisualID visualid);

		[CCode (cname = "XTestDiscard")]
		public static Status discard(Display display);
	}
}
x11
class Test : Object {
	public static void main(){
		string keystr = "XF86AudioPlay";

		stdout.printf("sizeof(char) = %lu, sizeof(int) = %lu, sizeof(long) = %lu\n",
			sizeof(char), sizeof(int), sizeof(long));

		stdout.printf("sizeof(X.KeyCode) = %lu, sizeof(X.KeySym) = %lu, sizeof(X.ID) = %lu\n",
			sizeof(X.KeyCode), sizeof(X.KeySym), sizeof(X.ID));

		X.Display display = new X.Display();
		stdout.printf("Display %s opened\n", display.display_string());

		X.KeySym keysym  = X.string_to_keysym(keystr);
		stdout.printf("String %s has keysym 0x%lX\n", keystr, keysym);

		X.KeyCode keycode = display.keysym_to_keycode(keysym);
		stdout.printf("Keysym 0x%lX has keycode %lu\n", keysym, keycode);

		X.Test.fake_key_event(display, (int) keycode, true, 0);
		stdout.printf("Keycode %lu pressed\n", keycode);
	
		X.Test.fake_key_event(display, (int) keycode, false, 0);
		stdout.printf("Keycode %lu released\n", keycode);

		display.flush();
		stdout.printf("Display %s flushed\n", display.display_string());
	}
}

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to