void handle_event(Display *display) { XEvent event; /* Get current event of X display */ int result = XNextEvent(display, &event); if (result == Success && event.type == PropertyNotify) { if (event.xproperty.atom == active_window_prop) { Window win = get_active_window(event.xproperty.display, event.xproperty.window); if (win != None && win != active_window) { if (active_window_name) XFree(active_window_name); if (active_window_class) XFree(active_window_class); get_window_class_name(display, win, &active_window_class, &active_window_name); active_window_pid = get_window_pid(display, win); fprintf(stdout, "%d - \"%s\", \"%s\" - %li ms\n", active_window_pid, active_window_class, active_window_name, event.xproperty.time - activation_time); active_window = win; activation_time = event.xproperty.time; } } } else { fprintf(stderr, "Couldn't fetch event, error code %d\n", result); } }
void button_handler(XEvent event,Display *display, ScreenInfos infos){ switch(event.xbutton.button){ case Button1: printf("---Left Button pressed---\n"); unsigned long _pid = get_window_pid(display, event.xbutton.window); printf("Check return value: %lu\n", _pid); break; case Button2: printf("---Mid Button pressed---\n"); if(event.xbutton.button==Button2){ Window cur_win = draw_window_with_name(display, event.xbutton.root, "TestWindow",infos.screen_num, 350,350, 200,200,BORDER_NONE, WhitePixel(display, infos.screen_num)); XMapWindow(display, cur_win); } break; case Button3: printf("---Right Button pressed---\n"); Window current_window = event.xbutton.subwindow; char *window_name; if(current_window!=None){ XFetchName(event.xbutton.display, current_window, &window_name); printf("Window name: %s - ", window_name); unsigned long _pid_kill = get_window_pid(display, event.xbutton.subwindow); XDestroyWindow(event.xbutton.display, current_window); printf("To kill: %ld -", _pid_kill); if(_pid_kill!=0){ kill(_pid_kill, SIGKILL); } printf("Current_Window != none"); } else { //XFetchName(event.xbutton.display, event.xbutton.window, &window_name); printf("Current_Window == none"); } printf(" Click on: %s\n", window_name); XFree(window_name); break; } printf("---End---\n"); }