static void process_cmds(void) { char line[VCHANNEL_MAX_LINE]; int size; char *p, *tok1, *tok2, *tok3, *tok4, *tok5, *tok6, *tok7, *tok8; while ((size = g_vchannel_read_fn(line, sizeof(line))) >= 0) { p = unescape(line); tok1 = get_token(&p); tok2 = get_token(&p); tok3 = get_token(&p); tok4 = get_token(&p); tok5 = get_token(&p); tok6 = get_token(&p); tok7 = get_token(&p); tok8 = get_token(&p); if (strcmp(tok1, "SYNC") == 0) do_sync(); else if (strcmp(tok1, "STATE") == 0) do_state(strtoul(tok2, NULL, 0), long_to_hwnd(strtoul(tok3, NULL, 0)), strtol(tok4, NULL, 0)); else if (strcmp(tok1, "POSITION") == 0) do_position(strtoul(tok2, NULL, 0), long_to_hwnd(strtoul(tok3, NULL, 0)), strtol(tok4, NULL, 0), strtol(tok5, NULL, 0), strtol(tok6, NULL, 0), strtol(tok7, NULL, 0)); else if (strcmp(tok1, "ZCHANGE") == 0) do_zchange(strtoul(tok2, NULL, 0), long_to_hwnd(strtoul(tok3, NULL, 0)), long_to_hwnd(strtoul(tok4, NULL, 0))); else if (strcmp(tok1, "FOCUS") == 0) do_focus(strtoul(tok2, NULL, 0), long_to_hwnd(strtoul(tok3, NULL, 0))); else if (strcmp(tok1, "DESTROY") == 0) do_destroy(long_to_hwnd(strtoul(tok3, NULL, 0))); else if (strcmp(tok1, "SPAWN") == 0) do_spawn(strtoul(tok2, NULL, 0), tok3); else if (strcmp(tok1, "PERSISTENT") == 0) do_persistent(strtoul(tok2, NULL, 0), strtol(tok3, NULL, 0)); free(p); } }
int main(int argc, char* argv[]){ char* action; Window window; int arg[5]={0}; // Connexion à un serveur X display = XOpenDisplay(NULL); if(!display){ printf("Can not open display.\n"); exit(EXIT_FAILURE); } // Récupère la valeur par default des différentes variables. screen = DefaultScreen(display); gc = DefaultGC (display, screen); root = RootWindow (display, screen); // Détermine l'action à effectuer : // On vérifie que le 2er argument (autre que nom fichier) est un id de fenetre : if(argc>2 && ((!strncmp(argv[2],"0x",2) && strtoll(argv[2],NULL,16)) || strtoll(argv[2],NULL,10)) ){ action = argv[1]; window = get_window(argv); // Si 5 arguments, c'est soit un move, soit un resize: if (argc==3){ // 1 seul argument (ex: 0x32422 ) if(!strcmp(action,"mapRaise")) do_map_and_raise(window); else if(!strcmp(action,"map")) do_map(window); else if(!strcmp(action,"raise")) do_raise(window); else if(!strcmp(action,"destroy")) do_destroy(window); else if(!strcmp(action,"focus")) do_focus(window); else if(!strcmp(action,"minimize")) do_minimize(window); else if(!strcmp(action,"set_desktop")) set_desktop((int)strtoll(argv[2],NULL,10)); else fail(); } else if(argc==4){ // 2 arguments (ex : 0x4242535 1 ) if(!strcmp(action,"set_desktop_for_window")){ set_desktop(strtoll(argv[3],NULL,10)); set_desktop_for_window(window,strtoll(argv[3],NULL,10)); } else if(!strcmp(action,"set_viewport")) set_viewport((int)strtoll(argv[2],NULL,10),(int)strtoll(argv[3],NULL,10)); else fail(); } else if(argc==5){ arg[0]=(int)strtoll(argv[3],NULL,10); arg[1]=(int)strtoll(argv[4],NULL,10); if(!strcmp(action,"move")) do_move(window, arg[0], arg[1]); else if(!strcmp(action,"resize")) do_resize(window,arg[0],arg[1]); else fail(); } else if(argc==7){ arg[0]=(int)strtoll(argv[3],NULL,10); arg[1]=(int)strtoll(argv[4],NULL,10); arg[2]=(int)strtoll(argv[5],NULL,10); arg[3]=(int)strtoll(argv[6],NULL,10); if(!strcmp(action,"moveResize")) do_move_and_resize(window, arg[0], arg[1], arg[2], arg[3]); else fail(); } else fail(); } else fail(); XCloseDisplay(display); return EXIT_SUCCESS; }