Created
November 27, 2013 06:00
-
-
Save fourdollars/7671312 to your computer and use it in GitHub Desktop.
A simple program to grab virtual core keyboard & pointer for 3 seconds.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -*- coding: utf-8; indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- */ | |
/** | |
* Copyright (C) 2013 Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com> | |
* | |
* 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, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* 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/>. | |
*/ | |
#include <stdio.h> | |
#include <gdk/gdk.h> | |
#include <gdk/gdkx.h> | |
static const char * | |
grab_string (int status) | |
{ | |
switch (status) { | |
case GDK_GRAB_SUCCESS: return "GrabSuccess"; | |
case GDK_GRAB_ALREADY_GRABBED: return "AlreadyGrabbed"; | |
case GDK_GRAB_INVALID_TIME: return "GrabInvalidTime"; | |
case GDK_GRAB_NOT_VIEWABLE: return "GrabNotViewable"; | |
case GDK_GRAB_FROZEN: return "GrabFrozen"; | |
default: | |
{ | |
static char foo [255]; | |
sprintf (foo, "unknown status: %d", status); | |
return foo; | |
} | |
} | |
} | |
static const char * | |
device_source (GdkDevice *device) | |
{ | |
switch (gdk_device_get_source (device)) { | |
case GDK_SOURCE_MOUSE: return "Mouse"; | |
case GDK_SOURCE_PEN: return "Pen"; | |
case GDK_SOURCE_ERASER: return "Eraser"; | |
case GDK_SOURCE_CURSOR: return "Cursor"; | |
case GDK_SOURCE_KEYBOARD: return "Keyboard"; | |
case GDK_SOURCE_TOUCHSCREEN: return "Touchscreen"; | |
case GDK_SOURCE_TOUCHPAD: return "Touchpad"; | |
default: return "Unknown"; | |
} | |
} | |
int | |
main(int argc, char* argv[]) | |
{ | |
GdkDisplay *display; | |
GdkWindow *window; | |
GdkScreen *screen; | |
GdkGrabStatus status; | |
GdkDeviceManager *manager; | |
GList *list, *it; | |
gdk_init (NULL, NULL); | |
display = gdk_display_get_default (); | |
screen = gdk_display_get_default_screen (display); | |
window = gdk_screen_get_root_window (screen); | |
manager = gdk_display_get_device_manager (display); | |
list = gdk_device_manager_list_devices (manager, GDK_DEVICE_TYPE_MASTER); | |
for (it = list; it; it = it->next) { | |
GdkDevice *device = (GdkDevice*) it->data; | |
printf ("name: %s\nsource: %s\n", gdk_device_get_name (device), device_source (device)); | |
status = gdk_device_grab (device, window, GDK_OWNERSHIP_NONE, TRUE, GDK_ALL_EVENTS_MASK, NULL, GDK_CURRENT_TIME); | |
printf ("status: %s\n", grab_string (status)); | |
} | |
sleep(3); | |
for (it = list; it; it = it->next) { | |
GdkDevice *device = (GdkDevice*) it->data; | |
gdk_device_ungrab (device, GDK_CURRENT_TIME); | |
} | |
g_list_free (list); | |
return 0; | |
} | |
/* vim:set fileencodings=utf-8 tabstop=4 expandtab shiftwidth=4 softtabstop=4: */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment