Advertisement
Guest User

Untitled

a guest
Oct 20th, 2012
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.79 KB | None | 0 0
  1. --- g15macro-1.0.3_orig/g15macro.c 2008-01-23 10:26:23.000000000 +0200
  2. +++ g15macro-1.0.3/g15macro.c 2012-10-20 19:01:44.794434743 +0300
  3. @@ -15,7 +15,7 @@
  4. along with g15daemon; if not, write to the Free Software
  5. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  6.  
  7. - (c) 2006-2007 Mike Lampard
  8. + (c) 2006-2007 Mike Lampard
  9.  
  10. $Revision: 445 $ - $Date: 2008-01-23 18:56:23 +1030 (Wed, 23 Jan 2008) $ $Author: mlampard $
  11.  
  12. @@ -41,7 +41,7 @@
  13. #include <sys/time.h>
  14. #include <config.h>
  15. #include <X11/Xlib.h>
  16. -#include <stdarg.h>
  17. +#include <stdarg.h>
  18. #ifdef HAVE_X11_EXTENSIONS_XTEST_H
  19. #include <X11/extensions/XTest.h>
  20. #endif
  21. @@ -52,11 +52,11 @@
  22. #include <libg15render.h>
  23. #include "config.h"
  24.  
  25. -#define XK_MISCELLANY
  26. +#define XK_MISCELLANY
  27. #define XK_LATIN1
  28. #define XK_LATIN2
  29. #include <X11/keysymdef.h>
  30. -
  31. +
  32. int g15screen_fd;
  33. int config_fd = 0;
  34. g15canvas *canvas;
  35. @@ -103,7 +103,7 @@
  36.  
  37. typedef struct mstates_s {
  38. gkeys_t gkeys[18];
  39. -}mstates_t;
  40. +}mstates_t;
  41.  
  42. mstates_t *mstates[3];
  43.  
  44. @@ -117,16 +117,6 @@
  45.  
  46. const int gkeycodes[] = { 177,152,190,208,129,130,231,209,210,136,220,143,246,251,137,138,133,183 };
  47.  
  48. -const int mmedia_codes[] = {164, 162, 144, 153, 174, 176};
  49. -
  50. -const long mmedia_defaults[] = {
  51. - XF86XK_AudioStop,
  52. - XF86XK_AudioPlay,
  53. - XF86XK_AudioPrev,
  54. - XF86XK_AudioNext,
  55. - XF86XK_AudioLowerVolume,
  56. - XF86XK_AudioRaiseVolume
  57. -};
  58. /* because this is an X11 client, we can work around the kernel limitations on key numbers */
  59. const long gkeydefaults[] = {
  60. /* M1 palette */
  61. @@ -137,16 +127,16 @@
  62. XF86XK_Launch8,
  63. XF86XK_Launch9,
  64. XF86XK_LaunchA,
  65. - XF86XK_LaunchB,
  66. - XF86XK_LaunchC,
  67. - XF86XK_LaunchD,
  68. - XF86XK_LaunchE,
  69. - XF86XK_LaunchF,
  70. - XF86XK_iTouch,
  71. - XF86XK_Calculater,
  72. - XF86XK_Support,
  73. - XF86XK_Word,
  74. - XF86XK_Messenger,
  75. + XF86XK_LaunchB,
  76. + XF86XK_LaunchC,
  77. + XF86XK_LaunchD,
  78. + XF86XK_LaunchE,
  79. + XF86XK_LaunchF,
  80. + XF86XK_iTouch,
  81. + XF86XK_Calculater,
  82. + XF86XK_Support,
  83. + XF86XK_Word,
  84. + XF86XK_Messenger,
  85. XF86XK_WebCam,
  86. /* M2 palette */
  87. XK_F13,
  88. @@ -228,14 +218,14 @@
  89. }
  90.  
  91. void fake_keyevent(int keycode,int keydown,unsigned long modifiers){
  92. - if(have_xtest && !recording) {
  93. - #ifdef HAVE_X11_EXTENSIONS_XTEST_H
  94. + if(have_xtest && !recording) {
  95. + #ifdef HAVE_X11_EXTENSIONS_XTEST_H
  96. pthread_mutex_lock(&x11mutex);
  97. XTestFakeKeyEvent(dpy, keycode,keydown, CurrentTime);
  98. XSync(dpy,False);
  99. pthread_mutex_unlock(&x11mutex);
  100. usleep(1500);
  101. - #endif
  102. + #endif
  103. } else {
  104. XKeyEvent event;
  105. Window current_focus;
  106. @@ -284,7 +274,7 @@
  107. g15r_renderString (canvas, (unsigned char *)"Canceled", 0, G15_TEXT_LARGE, 80-((strlen("Canceled")/2)*8), 18);
  108. g15_send(g15screen_fd,(char *)canvas->buffer,G15_BUFFER_LEN);
  109. record_cleanup();
  110. -}
  111. +}
  112.  
  113. void record_complete(unsigned long keystate)
  114. {
  115. @@ -292,7 +282,7 @@
  116. int gkey = map_gkey(keystate);
  117.  
  118. pthread_mutex_lock(&config_mutex);
  119. -
  120. +
  121. if(!rec_index) // nothing recorded - delete prior recording
  122. memset(mstates[mkey_state]->gkeys[gkey].keysequence.recorded_keypress,0,sizeof(keysequence_t));
  123. else
  124. @@ -300,7 +290,7 @@
  125.  
  126. mstates[mkey_state]->gkeys[gkey].keysequence.record_steps=rec_index;
  127. pthread_mutex_unlock(&config_mutex);
  128. -
  129. +
  130. memset(canvas->buffer,0,G15_BUFFER_LEN);
  131. if(rec_index){
  132. strcpy(tmpstr,"For key ");
  133. @@ -317,7 +307,7 @@
  134. g15r_renderString (canvas, (unsigned char *)"Deleted", 0, G15_TEXT_LARGE, 80-((strlen("Deleted")/2)*8), 18);
  135. }
  136. g15r_renderString (canvas, (unsigned char *)tmpstr, 0, G15_TEXT_LARGE, 80-((strlen(tmpstr)/2)*8), 32);
  137. -
  138. +
  139. g15_send(g15screen_fd,(char *)canvas->buffer,G15_BUFFER_LEN);
  140.  
  141. record_cleanup();
  142. @@ -349,7 +339,7 @@
  143. int gkey = map_gkey(keystate);
  144. if(gkey<0)
  145. return;
  146. -
  147. +
  148. /* if no macro has been recorded for this key, send the g15daemon default keycode */
  149. if(mstates[mkey_state]->gkeys[gkey].keysequence.record_steps==0){
  150. int mkey_offset=0;
  151. @@ -377,7 +367,7 @@
  152. key = XKeycodeToKeysym(dpy,mstates[mkey_state]->gkeys[gkey].keysequence.recorded_keypress[i].keycode,0);
  153. pthread_mutex_unlock(&x11mutex);
  154. g15macro_log("\t%s %s\n",XKeysymToString(key),mstates[mkey_state]->gkeys[gkey].keysequence.recorded_keypress[i].pressed?"Down":"Up");
  155. -
  156. +
  157. switch (key) {
  158. case XK_Control_L:
  159. case XK_Control_R:
  160. @@ -389,7 +379,7 @@
  161. case XK_Super_R:
  162. case XK_Hyper_L:
  163. case XK_Hyper_R:
  164. - usleep(mstates[mkey_state]->gkeys[gkey].keysequence.recorded_keypress[i].time_ms*1000);
  165. + usleep(mstates[mkey_state]->gkeys[gkey].keysequence.recorded_keypress[i].time_ms*1000);
  166. break;
  167. default:
  168. usleep(1000);
  169. @@ -431,9 +421,9 @@
  170. void save_macros(char *filename){
  171. FILE *configfile;
  172. configfile=fopen(filename,"w");
  173. -
  174. +
  175. dump_config(configfile);
  176. -
  177. +
  178. fclose(configfile);
  179. }
  180.  
  181. @@ -470,7 +460,7 @@
  182. mstates[mkey]->gkeys[key].keysequence.recorded_keypress[i].keycode = keycode;
  183. mstates[mkey]->gkeys[key].keysequence.recorded_keypress[i].pressed = strncmp(pressed,"Up",2)?1:0;
  184. mstates[mkey]->gkeys[key].keysequence.recorded_keypress[i].modifiers = modifiers;
  185. - mstates[mkey]->gkeys[key].keysequence.record_steps=++i;
  186. + mstates[mkey]->gkeys[key].keysequence.record_steps=++i;
  187. }
  188. } while(!feof(f));
  189. pthread_mutex_unlock(&config_mutex);
  190. @@ -491,34 +481,20 @@
  191.  
  192. }
  193.  
  194. -/* ensure that the multimedia keys are configured */
  195. -void configure_mmediakeys(){
  196. -
  197. - KeySym newmap[1];
  198. - int i=0;
  199. - pthread_mutex_lock(&x11mutex);
  200. - for(i=0;i<6;i++){
  201. - newmap[0]=mmedia_defaults[i];
  202. - XChangeKeyboardMapping (dpy, mmedia_codes[i], 1, newmap, 1);
  203. - }
  204. - XFlush(dpy);
  205. - pthread_mutex_unlock(&x11mutex);
  206. -
  207. -}
  208.  
  209. void handle_mkey_switch(unsigned int mkey) {
  210. - int mkey_offset = 0;
  211. + int mkey_offset = 0;
  212. switch(mkey) {
  213. case G15_KEY_M1:
  214. mled_state=G15_LED_M1;
  215. - mkey_state=0;
  216. + mkey_state=0;
  217. break;
  218. case G15_KEY_M2:
  219. - mled_state=G15_LED_M2;
  220. + mled_state=G15_LED_M2;
  221. mkey_state=1;
  222. break;
  223. case G15_KEY_M3:
  224. - mled_state=G15_LED_M3;
  225. + mled_state=G15_LED_M3;
  226. mkey_state=2;
  227. break;
  228. }
  229. @@ -551,14 +527,14 @@
  230. fds.revents=0;
  231. keystate=0;
  232. if ((poll(&fds, 1, 1000)) > 0) {
  233. - read (g15screen_fd, &keystate, sizeof (keystate));
  234. + read (g15screen_fd, &keystate, sizeof (keystate));
  235. }
  236. }
  237.  
  238. if (keystate!=0)
  239. {
  240. g15macro_log("Received Keystate == %lu\n",keystate);
  241. -
  242. +
  243. switch (keystate)
  244. {
  245. case G15_KEY_L5:{
  246. @@ -584,7 +560,7 @@
  247. pthread_mutex_lock(&x11mutex);
  248. XGrabKeyboard(dpy, root_win, True, GrabModeAsync, GrabModeAsync, CurrentTime);
  249. pthread_mutex_unlock(&x11mutex);
  250. - memset(&current_recording,0,sizeof(current_recording));
  251. + memset(&current_recording,0,sizeof(current_recording));
  252. } else {
  253. record_cancel();
  254. }
  255. @@ -647,7 +623,7 @@
  256. case XK_Super_R:
  257. case XK_Hyper_L:
  258. case XK_Hyper_R:
  259. - default:
  260. + default:
  261. press = False;
  262. }
  263. }
  264. @@ -662,17 +638,17 @@
  265. if(rec_index < MAX_KEYSTEPS) {
  266. rec_index++;
  267. /* now the default stuff */
  268. - pthread_mutex_lock(&x11mutex);
  269. + pthread_mutex_lock(&x11mutex);
  270. XUngrabKeyboard(dpy,CurrentTime);
  271. pthread_mutex_unlock(&x11mutex);
  272.  
  273. fake_keyevent(keycode,press,event->xkey.state);
  274. -
  275. +
  276. pthread_mutex_lock(&x11mutex);
  277. XGrabKeyboard(dpy, root_win, True, GrabModeAsync, GrabModeAsync, CurrentTime);
  278. XFlush(dpy);
  279. strcpy((char*)keytext,XKeysymToString(XKeycodeToKeysym(dpy, keycode, 0)));
  280. - pthread_mutex_unlock(&x11mutex);
  281. + pthread_mutex_unlock(&x11mutex);
  282. if(0==strcmp((char*)keytext,"space"))
  283. strcpy((char*)keytext," ");
  284. if(0==strcmp((char*)keytext,"period"))
  285. @@ -684,7 +660,7 @@
  286. g15_send(g15screen_fd,(char *)canvas->buffer,G15_BUFFER_LEN);
  287. }
  288. } else {
  289. - pthread_mutex_lock(&x11mutex);
  290. + pthread_mutex_lock(&x11mutex);
  291. XUngrabKeyboard(dpy,CurrentTime);
  292. pthread_mutex_unlock(&x11mutex);
  293. recording = 0;
  294. @@ -715,10 +691,10 @@
  295. case KeyPress:
  296. xkey_handler(&event);
  297. break;
  298. - case KeyRelease:
  299. + case KeyRelease:
  300. xkey_handler(&event);
  301. break;
  302. - case FocusIn:
  303. + case FocusIn:
  304. case FocusOut:
  305. case EnterNotify:
  306. case LeaveNotify:
  307. @@ -741,7 +717,7 @@
  308. default:
  309. g15macro_log("Unhandled event (%i) received\n",event.type);
  310. }
  311. - }else
  312. + }else
  313. usleep(25000);
  314. }
  315. return NULL;
  316. @@ -779,7 +755,7 @@
  317. #ifdef USE_XTEST
  318. int xtest_major_version = 0;
  319. int xtest_minor_version = 0;
  320. -#endif
  321. +#endif
  322. struct sigaction new_action;
  323. int dummy=0,i=0;
  324. unsigned char user[256];
  325. @@ -853,22 +829,21 @@
  326.  
  327. /* completely ignore errors and carry on */
  328. XSetErrorHandler(myx_error_handler);
  329. - configure_mmediakeys();
  330. change_keymap(0);
  331. XFlush(dpy);
  332. -
  333. - if(keysonly>0)
  334. +
  335. + if(keysonly>0)
  336. goto close_and_exit;
  337.  
  338. /* old binary config format */
  339. strncat(configpath,"/.g15macro",1024-strlen(configpath));
  340. strncat(configpath,"/g15macro-data",1024-strlen(configpath));
  341. config_fd = open(configpath,O_RDONLY|O_SYNC);
  342. -
  343. +
  344. mstates[0] = malloc(sizeof(mstates_t));
  345. mstates[1] = (mstates_t*)malloc(sizeof(mstates_t));
  346. mstates[2] = (mstates_t*)malloc(sizeof(mstates_t));
  347. -
  348. +
  349. if(config_fd>0) {
  350. printf("Converting old data\n");
  351. read(config_fd,mstates[0],sizeof(mstates_t));
  352. @@ -895,7 +870,7 @@
  353. strncat(configpath,"/g15macro.conf",1024-strlen(configpath));
  354. config=fopen(configpath,"a");
  355. fclose(config);
  356. -
  357. +
  358. do {
  359. if((g15screen_fd = new_g15_screen(G15_G15RBUF))<0){
  360. printf("Sorry, cant connect to the G15daemon - retrying\n");
  361. @@ -911,7 +886,7 @@
  362. dump_config(stderr);
  363. exit(0);
  364. }
  365. -
  366. +
  367. g15_send_cmd (g15screen_fd,G15DAEMON_KEY_HANDLER, dummy);
  368. usleep(1000);
  369. g15_send_cmd (g15screen_fd,G15DAEMON_MKEYLEDS,mled_state);
  370. @@ -946,28 +921,28 @@
  371. printf("XTest disabled by configure: no devel package was found. Using XSendEvent instead.\n");
  372. #endif
  373.  
  374. -
  375. +
  376. new_action.sa_handler = g15macro_sighandler;
  377. new_action.sa_flags = 0;
  378. sigaction(SIGINT, &new_action, NULL);
  379. sigaction(SIGQUIT, &new_action, NULL);
  380. sigaction(SIGTERM, &new_action, NULL);
  381. sigaction(SIGPIPE, &new_action, NULL);
  382. -
  383. +
  384. snprintf((char*)splashpath,1024,"%s/%s",DATADIR,"g15macro/splash/g15macro.wbmp");
  385. g15r_loadWbmpSplash(canvas, splashpath);
  386. g15_send(g15screen_fd,(char *)canvas->buffer,G15_BUFFER_LEN);
  387. #ifdef G15DAEMON_NEVER_SELECT
  388. g15_send_cmd (g15screen_fd, G15DAEMON_NEVER_SELECT, dummy);
  389. #endif
  390. -
  391. +
  392. usleep(1000);
  393. pthread_mutex_init(&x11mutex,NULL);
  394. pthread_mutex_init(&config_mutex,NULL);
  395. pthread_attr_t attr;
  396. pthread_attr_init(&attr);
  397. int thread_policy=SCHED_FIFO;
  398. - pthread_attr_setschedpolicy(&attr,thread_policy);
  399. + pthread_attr_setschedpolicy(&attr,thread_policy);
  400. pthread_attr_setstacksize(&attr,32*1024); /* set stack to 32k - dont need 8Mb !! */
  401.  
  402. pthread_create(&Xkeys, &attr, xevent_thread, NULL);
  403. @@ -983,7 +958,7 @@
  404.  
  405. if(display_timeout<=0){
  406. int fg_check = g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, dummy);
  407. - if (fg_check==1) { // foreground
  408. + if (fg_check==1) { // foreground
  409. do {
  410. g15_send_cmd (g15screen_fd, G15DAEMON_SWITCH_PRIORITIES, dummy);
  411. } while(g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, dummy)==1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement