1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
/** \file
* \brief Motif Driver implementation of iupdrvSetGlobal
*
* See Copyright Notice in "iup.h"
*/
#include <Xm/Xm.h>
#include <stdio.h>
#include "iup.h"
#include "iup_str.h"
#include "iup_drv.h"
#include "iup_drvinfo.h"
#include "iup_strmessage.h"
#include "iupmot_drv.h"
static void motGlobalSendKey(int key, int press)
{
Window focus;
int revert_to;
XKeyEvent evt;
memset(&evt, 0, sizeof(XKeyEvent));
evt.display = iupmot_display;
evt.send_event = True;
evt.root = DefaultRootWindow(iupmot_display);
XGetInputFocus(iupmot_display, &focus, &revert_to);
evt.window = focus;
iupmotKeyEncode(key, &evt.keycode, &evt.state);
if (!evt.keycode)
return;
if (press & 0x01)
{
evt.type = KeyPress;
XSendEvent(iupmot_display, (Window)InputFocus, False, KeyPressMask, (XEvent*)&evt);
}
if (press & 0x02)
{
evt.type = KeyRelease;
XSendEvent(iupmot_display, (Window)InputFocus, False, KeyReleaseMask, (XEvent*)&evt);
}
}
int iupdrvSetGlobal(const char *name, const char *value)
{
if (iupStrEqual(name, "LANGUAGE"))
{
iupStrMessageUpdateLanguage(value);
return 1;
}
if (iupStrEqual(name, "AUTOREPEAT"))
{
XKeyboardControl values;
if (iupStrBoolean(value))
values.auto_repeat_mode = 1;
else
values.auto_repeat_mode = 0;
XChangeKeyboardControl(iupmot_display, KBAutoRepeatMode, &values);
return 0;
}
if (iupStrEqual(name, "CURSORPOS"))
{
int x, y;
if (iupStrToIntInt(value, &x, &y, 'x') == 2)
XWarpPointer(iupmot_display,None,RootWindow(iupmot_display, iupmot_screen),0,0,0,0,x,y);
return 0;
}
if (iupStrEqual(name, "KEYPRESS"))
{
int key;
if (iupStrToInt(value, &key))
motGlobalSendKey(key, 0x01);
return 0;
}
if (iupStrEqual(name, "KEYRELEASE"))
{
int key;
if (iupStrToInt(value, &key))
motGlobalSendKey(key, 0x02);
return 0;
}
if (iupStrEqual(name, "KEY"))
{
int key;
if (iupStrToInt(value, &key))
motGlobalSendKey(key, 0x03);
return 0;
}
return 1;
}
char* iupdrvGetGlobal(const char *name)
{
if (iupStrEqual(name, "CURSORPOS"))
{
int x, y;
char* str = iupStrGetMemory(50);
iupdrvGetCursorPos(&x, &y);
sprintf(str, "%dx%d", x, y);
return str;
}
if (iupStrEqual(name, "SHIFTKEY"))
{
char key[5];
iupdrvGetKeyState(key);
if (key[0] == 'S')
return "ON";
return "OFF";
}
if (iupStrEqual(name, "CONTROLKEY"))
{
char key[5];
iupdrvGetKeyState(key);
if (key[1] == 'C')
return "ON";
return "OFF";
}
if (iupStrEqual(name, "MODKEYSTATE"))
{
char *str = iupStrGetMemory(5);
iupdrvGetKeyState(str);
return str;
}
if (iupStrEqual(name, "SCREENSIZE"))
{
char *str = iupStrGetMemory(50);
int w, h;
iupdrvGetScreenSize(&w, &h);
sprintf(str, "%dx%d", w, h);
return str;
}
if (iupStrEqual(name, "FULLSIZE"))
{
char *str = iupStrGetMemory(50);
int w, h;
iupdrvGetFullSize(&w, &h);
sprintf(str, "%dx%d", w, h);
return str;
}
if (iupStrEqual(name, "SCREENDEPTH"))
{
char *str = iupStrGetMemory(50);
int bpp = iupdrvGetScreenDepth();
sprintf(str, "%d", bpp);
return str;
}
return NULL;
}
|