Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- g15macro-1.0.3_orig/g15macro.c 2008-01-23 10:26:23.000000000 +0200
- +++ g15macro-1.0.3/g15macro.c 2012-10-20 19:01:44.794434743 +0300
- @@ -15,7 +15,7 @@
- along with g15daemon; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- - (c) 2006-2007 Mike Lampard
- + (c) 2006-2007 Mike Lampard
- $Revision: 445 $ - $Date: 2008-01-23 18:56:23 +1030 (Wed, 23 Jan 2008) $ $Author: mlampard $
- @@ -41,7 +41,7 @@
- #include <sys/time.h>
- #include <config.h>
- #include <X11/Xlib.h>
- -#include <stdarg.h>
- +#include <stdarg.h>
- #ifdef HAVE_X11_EXTENSIONS_XTEST_H
- #include <X11/extensions/XTest.h>
- #endif
- @@ -52,11 +52,11 @@
- #include <libg15render.h>
- #include "config.h"
- -#define XK_MISCELLANY
- +#define XK_MISCELLANY
- #define XK_LATIN1
- #define XK_LATIN2
- #include <X11/keysymdef.h>
- -
- +
- int g15screen_fd;
- int config_fd = 0;
- g15canvas *canvas;
- @@ -103,7 +103,7 @@
- typedef struct mstates_s {
- gkeys_t gkeys[18];
- -}mstates_t;
- +}mstates_t;
- mstates_t *mstates[3];
- @@ -117,16 +117,6 @@
- const int gkeycodes[] = { 177,152,190,208,129,130,231,209,210,136,220,143,246,251,137,138,133,183 };
- -const int mmedia_codes[] = {164, 162, 144, 153, 174, 176};
- -
- -const long mmedia_defaults[] = {
- - XF86XK_AudioStop,
- - XF86XK_AudioPlay,
- - XF86XK_AudioPrev,
- - XF86XK_AudioNext,
- - XF86XK_AudioLowerVolume,
- - XF86XK_AudioRaiseVolume
- -};
- /* because this is an X11 client, we can work around the kernel limitations on key numbers */
- const long gkeydefaults[] = {
- /* M1 palette */
- @@ -137,16 +127,16 @@
- XF86XK_Launch8,
- XF86XK_Launch9,
- XF86XK_LaunchA,
- - XF86XK_LaunchB,
- - XF86XK_LaunchC,
- - XF86XK_LaunchD,
- - XF86XK_LaunchE,
- - XF86XK_LaunchF,
- - XF86XK_iTouch,
- - XF86XK_Calculater,
- - XF86XK_Support,
- - XF86XK_Word,
- - XF86XK_Messenger,
- + XF86XK_LaunchB,
- + XF86XK_LaunchC,
- + XF86XK_LaunchD,
- + XF86XK_LaunchE,
- + XF86XK_LaunchF,
- + XF86XK_iTouch,
- + XF86XK_Calculater,
- + XF86XK_Support,
- + XF86XK_Word,
- + XF86XK_Messenger,
- XF86XK_WebCam,
- /* M2 palette */
- XK_F13,
- @@ -228,14 +218,14 @@
- }
- void fake_keyevent(int keycode,int keydown,unsigned long modifiers){
- - if(have_xtest && !recording) {
- - #ifdef HAVE_X11_EXTENSIONS_XTEST_H
- + if(have_xtest && !recording) {
- + #ifdef HAVE_X11_EXTENSIONS_XTEST_H
- pthread_mutex_lock(&x11mutex);
- XTestFakeKeyEvent(dpy, keycode,keydown, CurrentTime);
- XSync(dpy,False);
- pthread_mutex_unlock(&x11mutex);
- usleep(1500);
- - #endif
- + #endif
- } else {
- XKeyEvent event;
- Window current_focus;
- @@ -284,7 +274,7 @@
- g15r_renderString (canvas, (unsigned char *)"Canceled", 0, G15_TEXT_LARGE, 80-((strlen("Canceled")/2)*8), 18);
- g15_send(g15screen_fd,(char *)canvas->buffer,G15_BUFFER_LEN);
- record_cleanup();
- -}
- +}
- void record_complete(unsigned long keystate)
- {
- @@ -292,7 +282,7 @@
- int gkey = map_gkey(keystate);
- pthread_mutex_lock(&config_mutex);
- -
- +
- if(!rec_index) // nothing recorded - delete prior recording
- memset(mstates[mkey_state]->gkeys[gkey].keysequence.recorded_keypress,0,sizeof(keysequence_t));
- else
- @@ -300,7 +290,7 @@
- mstates[mkey_state]->gkeys[gkey].keysequence.record_steps=rec_index;
- pthread_mutex_unlock(&config_mutex);
- -
- +
- memset(canvas->buffer,0,G15_BUFFER_LEN);
- if(rec_index){
- strcpy(tmpstr,"For key ");
- @@ -317,7 +307,7 @@
- g15r_renderString (canvas, (unsigned char *)"Deleted", 0, G15_TEXT_LARGE, 80-((strlen("Deleted")/2)*8), 18);
- }
- g15r_renderString (canvas, (unsigned char *)tmpstr, 0, G15_TEXT_LARGE, 80-((strlen(tmpstr)/2)*8), 32);
- -
- +
- g15_send(g15screen_fd,(char *)canvas->buffer,G15_BUFFER_LEN);
- record_cleanup();
- @@ -349,7 +339,7 @@
- int gkey = map_gkey(keystate);
- if(gkey<0)
- return;
- -
- +
- /* if no macro has been recorded for this key, send the g15daemon default keycode */
- if(mstates[mkey_state]->gkeys[gkey].keysequence.record_steps==0){
- int mkey_offset=0;
- @@ -377,7 +367,7 @@
- key = XKeycodeToKeysym(dpy,mstates[mkey_state]->gkeys[gkey].keysequence.recorded_keypress[i].keycode,0);
- pthread_mutex_unlock(&x11mutex);
- g15macro_log("\t%s %s\n",XKeysymToString(key),mstates[mkey_state]->gkeys[gkey].keysequence.recorded_keypress[i].pressed?"Down":"Up");
- -
- +
- switch (key) {
- case XK_Control_L:
- case XK_Control_R:
- @@ -389,7 +379,7 @@
- case XK_Super_R:
- case XK_Hyper_L:
- case XK_Hyper_R:
- - usleep(mstates[mkey_state]->gkeys[gkey].keysequence.recorded_keypress[i].time_ms*1000);
- + usleep(mstates[mkey_state]->gkeys[gkey].keysequence.recorded_keypress[i].time_ms*1000);
- break;
- default:
- usleep(1000);
- @@ -431,9 +421,9 @@
- void save_macros(char *filename){
- FILE *configfile;
- configfile=fopen(filename,"w");
- -
- +
- dump_config(configfile);
- -
- +
- fclose(configfile);
- }
- @@ -470,7 +460,7 @@
- mstates[mkey]->gkeys[key].keysequence.recorded_keypress[i].keycode = keycode;
- mstates[mkey]->gkeys[key].keysequence.recorded_keypress[i].pressed = strncmp(pressed,"Up",2)?1:0;
- mstates[mkey]->gkeys[key].keysequence.recorded_keypress[i].modifiers = modifiers;
- - mstates[mkey]->gkeys[key].keysequence.record_steps=++i;
- + mstates[mkey]->gkeys[key].keysequence.record_steps=++i;
- }
- } while(!feof(f));
- pthread_mutex_unlock(&config_mutex);
- @@ -491,34 +481,20 @@
- }
- -/* ensure that the multimedia keys are configured */
- -void configure_mmediakeys(){
- -
- - KeySym newmap[1];
- - int i=0;
- - pthread_mutex_lock(&x11mutex);
- - for(i=0;i<6;i++){
- - newmap[0]=mmedia_defaults[i];
- - XChangeKeyboardMapping (dpy, mmedia_codes[i], 1, newmap, 1);
- - }
- - XFlush(dpy);
- - pthread_mutex_unlock(&x11mutex);
- -
- -}
- void handle_mkey_switch(unsigned int mkey) {
- - int mkey_offset = 0;
- + int mkey_offset = 0;
- switch(mkey) {
- case G15_KEY_M1:
- mled_state=G15_LED_M1;
- - mkey_state=0;
- + mkey_state=0;
- break;
- case G15_KEY_M2:
- - mled_state=G15_LED_M2;
- + mled_state=G15_LED_M2;
- mkey_state=1;
- break;
- case G15_KEY_M3:
- - mled_state=G15_LED_M3;
- + mled_state=G15_LED_M3;
- mkey_state=2;
- break;
- }
- @@ -551,14 +527,14 @@
- fds.revents=0;
- keystate=0;
- if ((poll(&fds, 1, 1000)) > 0) {
- - read (g15screen_fd, &keystate, sizeof (keystate));
- + read (g15screen_fd, &keystate, sizeof (keystate));
- }
- }
- if (keystate!=0)
- {
- g15macro_log("Received Keystate == %lu\n",keystate);
- -
- +
- switch (keystate)
- {
- case G15_KEY_L5:{
- @@ -584,7 +560,7 @@
- pthread_mutex_lock(&x11mutex);
- XGrabKeyboard(dpy, root_win, True, GrabModeAsync, GrabModeAsync, CurrentTime);
- pthread_mutex_unlock(&x11mutex);
- - memset(¤t_recording,0,sizeof(current_recording));
- + memset(¤t_recording,0,sizeof(current_recording));
- } else {
- record_cancel();
- }
- @@ -647,7 +623,7 @@
- case XK_Super_R:
- case XK_Hyper_L:
- case XK_Hyper_R:
- - default:
- + default:
- press = False;
- }
- }
- @@ -662,17 +638,17 @@
- if(rec_index < MAX_KEYSTEPS) {
- rec_index++;
- /* now the default stuff */
- - pthread_mutex_lock(&x11mutex);
- + pthread_mutex_lock(&x11mutex);
- XUngrabKeyboard(dpy,CurrentTime);
- pthread_mutex_unlock(&x11mutex);
- fake_keyevent(keycode,press,event->xkey.state);
- -
- +
- pthread_mutex_lock(&x11mutex);
- XGrabKeyboard(dpy, root_win, True, GrabModeAsync, GrabModeAsync, CurrentTime);
- XFlush(dpy);
- strcpy((char*)keytext,XKeysymToString(XKeycodeToKeysym(dpy, keycode, 0)));
- - pthread_mutex_unlock(&x11mutex);
- + pthread_mutex_unlock(&x11mutex);
- if(0==strcmp((char*)keytext,"space"))
- strcpy((char*)keytext," ");
- if(0==strcmp((char*)keytext,"period"))
- @@ -684,7 +660,7 @@
- g15_send(g15screen_fd,(char *)canvas->buffer,G15_BUFFER_LEN);
- }
- } else {
- - pthread_mutex_lock(&x11mutex);
- + pthread_mutex_lock(&x11mutex);
- XUngrabKeyboard(dpy,CurrentTime);
- pthread_mutex_unlock(&x11mutex);
- recording = 0;
- @@ -715,10 +691,10 @@
- case KeyPress:
- xkey_handler(&event);
- break;
- - case KeyRelease:
- + case KeyRelease:
- xkey_handler(&event);
- break;
- - case FocusIn:
- + case FocusIn:
- case FocusOut:
- case EnterNotify:
- case LeaveNotify:
- @@ -741,7 +717,7 @@
- default:
- g15macro_log("Unhandled event (%i) received\n",event.type);
- }
- - }else
- + }else
- usleep(25000);
- }
- return NULL;
- @@ -779,7 +755,7 @@
- #ifdef USE_XTEST
- int xtest_major_version = 0;
- int xtest_minor_version = 0;
- -#endif
- +#endif
- struct sigaction new_action;
- int dummy=0,i=0;
- unsigned char user[256];
- @@ -853,22 +829,21 @@
- /* completely ignore errors and carry on */
- XSetErrorHandler(myx_error_handler);
- - configure_mmediakeys();
- change_keymap(0);
- XFlush(dpy);
- -
- - if(keysonly>0)
- +
- + if(keysonly>0)
- goto close_and_exit;
- /* old binary config format */
- strncat(configpath,"/.g15macro",1024-strlen(configpath));
- strncat(configpath,"/g15macro-data",1024-strlen(configpath));
- config_fd = open(configpath,O_RDONLY|O_SYNC);
- -
- +
- mstates[0] = malloc(sizeof(mstates_t));
- mstates[1] = (mstates_t*)malloc(sizeof(mstates_t));
- mstates[2] = (mstates_t*)malloc(sizeof(mstates_t));
- -
- +
- if(config_fd>0) {
- printf("Converting old data\n");
- read(config_fd,mstates[0],sizeof(mstates_t));
- @@ -895,7 +870,7 @@
- strncat(configpath,"/g15macro.conf",1024-strlen(configpath));
- config=fopen(configpath,"a");
- fclose(config);
- -
- +
- do {
- if((g15screen_fd = new_g15_screen(G15_G15RBUF))<0){
- printf("Sorry, cant connect to the G15daemon - retrying\n");
- @@ -911,7 +886,7 @@
- dump_config(stderr);
- exit(0);
- }
- -
- +
- g15_send_cmd (g15screen_fd,G15DAEMON_KEY_HANDLER, dummy);
- usleep(1000);
- g15_send_cmd (g15screen_fd,G15DAEMON_MKEYLEDS,mled_state);
- @@ -946,28 +921,28 @@
- printf("XTest disabled by configure: no devel package was found. Using XSendEvent instead.\n");
- #endif
- -
- +
- new_action.sa_handler = g15macro_sighandler;
- new_action.sa_flags = 0;
- sigaction(SIGINT, &new_action, NULL);
- sigaction(SIGQUIT, &new_action, NULL);
- sigaction(SIGTERM, &new_action, NULL);
- sigaction(SIGPIPE, &new_action, NULL);
- -
- +
- snprintf((char*)splashpath,1024,"%s/%s",DATADIR,"g15macro/splash/g15macro.wbmp");
- g15r_loadWbmpSplash(canvas, splashpath);
- g15_send(g15screen_fd,(char *)canvas->buffer,G15_BUFFER_LEN);
- #ifdef G15DAEMON_NEVER_SELECT
- g15_send_cmd (g15screen_fd, G15DAEMON_NEVER_SELECT, dummy);
- #endif
- -
- +
- usleep(1000);
- pthread_mutex_init(&x11mutex,NULL);
- pthread_mutex_init(&config_mutex,NULL);
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- int thread_policy=SCHED_FIFO;
- - pthread_attr_setschedpolicy(&attr,thread_policy);
- + pthread_attr_setschedpolicy(&attr,thread_policy);
- pthread_attr_setstacksize(&attr,32*1024); /* set stack to 32k - dont need 8Mb !! */
- pthread_create(&Xkeys, &attr, xevent_thread, NULL);
- @@ -983,7 +958,7 @@
- if(display_timeout<=0){
- int fg_check = g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, dummy);
- - if (fg_check==1) { // foreground
- + if (fg_check==1) { // foreground
- do {
- g15_send_cmd (g15screen_fd, G15DAEMON_SWITCH_PRIORITIES, dummy);
- } while(g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, dummy)==1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement