Desktop

/* $Id: callbacks.c,v 1.1 2010/07/25 08:12:04 khorben Exp $ */
/* Copyright (c) 2010 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Keyboard */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifdef DEBUG
# include <stdio.h>
#endif
#include <string.h>
#include <X11/extensions/XTest.h>
#include <gdk/gdkx.h>
#include "keyboard.h"
#include "callbacks.h"
/* public */
/* functions */
/* on_keyboard_delete_event */
gboolean on_keyboard_delete_event(gpointer data)
{
Keyboard * keyboard = data;
keyboard_show(keyboard, FALSE);
gtk_main_quit();
return TRUE;
}
/* on_keyboard_key_clicked */
void on_keyboard_key_clicked(gpointer data, GtkWidget * key)
{
Keyboard * keyboard = data;
unsigned int * keysym;
unsigned int keycode;
Display * display;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s(%p, \"%s\")\n", __func__, keyboard,
gtk_button_get_label(GTK_BUTTON(key)));
#endif
if((keysym = g_object_get_data(G_OBJECT(key), "keysym")) == NULL)
return;
display = gdk_x11_get_default_xdisplay();
keycode = XKeysymToKeycode(display, *keysym);
XTestGrabControl(display, True);
XTestFakeKeyEvent(display, keycode, True, 0);
XTestFakeKeyEvent(display, keycode, False, 0);
XTestGrabControl(display, False);
}