void * getNextKey(void *) { XDeviceInfo *info; Display *display; display = XOpenDisplay(NULL); Bool handle_proximity = False; info = find_device_info(display, device, True); if (!info) { //fprintf(stderr, "unable to find device '%s'\n", argv[idx]); //return EXIT_FAILURE; } else { if (register_events(display, info, device, handle_proximity)) { print_events(display); } else { fprintf(stderr, "no event registered...\n"); //return EXIT_FAILURE; } } //return output; }
InputDevice_XInput::InputDevice_XInput(Display* dpy, Window w, const std::string& name_) : name(name_), absolute(false), num_keys (0), proximity(false), motion_type (INVALID_EVENT_TYPE), button_press_type (INVALID_EVENT_TYPE), button_release_type(INVALID_EVENT_TYPE), key_press_type (INVALID_EVENT_TYPE), key_release_type (INVALID_EVENT_TYPE), proximity_in_type (INVALID_EVENT_TYPE), proximity_out_type (INVALID_EVENT_TYPE) { //std::cout << "WindowRect: " << window_rect << std::endl; XDeviceInfo* info = find_device_info(dpy, name.c_str(), True); if (!info) std::cout << "InputDeviceXInput Error: Couldn't find device: " << name << std::endl; get_info(info); if (!register_events(dpy, info, name.c_str(), True)) { std::cout << "debug" << "InputDeviceXInput: Couldn't find device: " << name << std::endl; } else { //slot_xevent = owner->sig_unknown_xevent.connect(this, &InputDevice_XInput::on_xevent); } }
/* ------------------------------------------------------------------------- */ PLUGIN_MENU_PUBLIC_API PLUGIN_INIT() { struct plugin_t* plugin; /* init global data */ glob_create(game); /* init plugin */ plugin = plugin_create(game, PLUGIN_NAME, PLUGIN_CATEGORY, PLUGIN_AUTHOR, PLUGIN_DESCRIPTION, PLUGIN_WEBSITE ); get_global(game)->plugin = plugin; /* set plugin information - Change this in the file "CMakeLists.txt" */ plugin_set_programming_language(plugin, PLUGIN_PROGRAMMING_LANGUAGE_C ); plugin_set_version(plugin, PLUGIN_VERSION_MAJOR, PLUGIN_VERSION_MINOR, PLUGIN_VERSION_PATCH ); register_services(plugin); register_events(plugin); return plugin; }
void handle_events(void) { int i, wn; xcb_window_t *wc, wid = 0; xcb_generic_event_t *e; xcb_create_notify_event_t *ec; /* * We need to get notifed of window creations, no matter what, because * we need to register the event mask on all newly created windows */ register_events(scr->root, XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY); if (mask & XCB_EVENT_MASK_BUTTON_PRESS) { xcb_grab_button(conn, 0, scr->root, XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, scr->root, XCB_NONE, 1, XCB_NONE); } /* register the events on all mapped windows */ wn = get_windows(conn, scr->root, &wc); for (i=0; i<wn; i++) register_events(wc[i], mask); xcb_flush(conn); for(;;) { e = xcb_wait_for_event(conn); switch (e->response_type & ~0x80) { case XCB_CREATE_NOTIFY: ec = (xcb_create_notify_event_t*)e; register_events(ec->window, mask); default: wid = get_window_id(e); } if (wid > 0) { printf("%d:0x%08x\n", e->response_type, wid); fflush(stdout); } } }
/* initializes XInput devices */ static void XInputDevices_init(void) { int i,j,k; fprintf(stderr, "XInput: Initialization...\n"); if (!XQueryExtension(display,"XInputExtension",&i,&j,&k)) { fprintf(stderr,"XInput: Your Xserver doesn't support XInput Extensions\n"); return; } /* parse all devicenames */ for(i=0;i<XINPUT_MAX_NUM_DEVICES;++i) { if (XIdevices[i].deviceName) { /* if not NULL, check for an existing device */ XIdevices[i].info=find_device_info(display,XIdevices[i].deviceName,True); if (! XIdevices[i].info) { fprintf(stderr,"XInput: Unable to find device `%s'. Ignoring it!\n", XIdevices[i].deviceName); XIdevices[i].deviceName=NULL; } else { /* ok, found a device, now register device for motion events */ if (i < XINPUT_JOYSTICK_1) { XIdevices[i].mameDevice=XMAME_TRACKBALL; } else { /* prepared for XInput-Joysticks XIdevices[i].mameDevice=XMAME_JOYSTICK; */ } if (! register_events(i, display,XIdevices[i].info,XIdevices[i].deviceName)) { fprintf(stderr,"XInput: Couldn't register device `%s' for events. Ignoring it\n", XIdevices[i].deviceName); XIdevices[i].deviceName=NULL; } } } } }
int main(int argc, char *argv[], char *env[]) { char *display_name = NULL; char *device_name = NULL; char *output_name = NULL; XSetWindowAttributes xswa; int i = 0; double a, a1, a2, b, b1, b2, xerr, yerr; int xi_opcode, event, error; XExtensionVersion *version; XDeviceInfo *info; XDevice *device; long calib_data[4]; unsigned long mask; unsigned char swap; int keep_cursor = 0, ch; /* Crosshair placement */ int cpx[] = { 0, 0, 1, 1, 1 }; int cpy[] = { 0, 1, 0, 0, 1 }; while ((ch = getopt(argc, argv, "cD:d:o:v")) != -1) { switch (ch) { case 'c': keep_cursor++; break; case 'D': display_name = optarg; break; case 'd': device_name = optarg; break; case 'o': output_name = optarg; break; case 'v': verbose = True; break; default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; if (argc != 0) usage(); /* connect to X server */ if ((display = XOpenDisplay(display_name)) == NULL) { fprintf(stderr, "%s: cannot connect to X server %s\n", __progname, XDisplayName(display_name)); exit(1); } screen = DefaultScreen(display); root = RootWindow(display, screen); /* get screen size from display structure macro */ xpos = 0; ypos = 0; width = DisplayWidth(display, screen); height = DisplayHeight(display, screen); if (XRRQueryExtension(display, &event, &error)) { int major, minor; if (XRRQueryVersion(display, &major, &minor) != True) { fprintf(stderr, "Error querying XRandR version"); } else { printf("XRandR extension version %d.%d present\n", major, minor); has_xrandr = True; if (major > 1 || (major == 1 && minor >=2)) has_xrandr_1_2 = True; if (major > 1 || (major == 1 && minor >=3)) has_xrandr_1_3 = True; } } if (output_name != NULL) { if (has_xrandr_1_2) { get_xrandr_config(display, root, output_name, &xpos, &ypos, &width, &height); } else { fprintf(stderr, "%s: can not specify an output " "whithout XRandr 1.2 or later", __progname); exit(2); } } if (!XQueryExtension(display, INAME, &xi_opcode, &event, &error)) { fprintf(stderr, "%s: X Input extension not available.\n", __progname); exit(1); } version = XGetExtensionVersion(display, INAME); if (version == NULL || version == (XExtensionVersion *)NoSuchExtension) { fprintf(stderr, "Cannot query X Input version.\n"); exit(1); } XFree(version); prop_calibration = XInternAtom(display, WS_PROP_CALIBRATION, True); if (prop_calibration == None) { fprintf(stderr, "Unable to find the \"%s\" device property.\n" "There are probably no calibrable devices " "on this system.\n", WS_PROP_CALIBRATION); exit(1); } prop_swap = XInternAtom(display, WS_PROP_SWAP_AXES, True); if (prop_swap == None) { fprintf(stderr, "Unable to find the \"%s\" device property\n", WS_PROP_SWAP_AXES); exit(1); } info = find_device_info(device_name); if (info == NULL) { fprintf(stderr, "Unable to find the %s device\n", device_name ? device_name : "default"); exit(1); } /* setup window attributes */ xswa.override_redirect = True; xswa.background_pixel = BlackPixel(display, screen); xswa.event_mask = ExposureMask | KeyPressMask; mask = CWOverrideRedirect | CWBackPixel | CWEventMask; if (!keep_cursor) { xswa.cursor = create_empty_cursor(); mask |= CWCursor; } win = XCreateWindow(display, RootWindow(display, screen), xpos, ypos, width, height, 0, CopyFromParent, InputOutput, CopyFromParent, mask, &xswa); render_init(); XMapWindow(display, win); XGrabKeyboard(display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime); XGrabServer(display); XClearWindow(display, win); if (verbose) printf("Calibrating %s\n", info->name); device = XOpenDevice(display, info->id); if (!device) { fprintf(stderr, "Unable to open the X input device \"%s\"\n", info->name); return 0; } if (!register_events(info, device, 0)) exit(1); uncalibrate(device); calib: XftDrawRect(draw, &bg, 0, 0, width, height); for (i = 0; i < 5; i++) { draw_graphics(cpx[i], cpy[i], i); XFlush(display); if (!get_events(i)) break; XftDrawRect(draw, &bg, 0, 0, width, height); } if (interrupted) cleanup_exit(device); /* Check if X and Y should be swapped */ if (fabs(x[0] - x[1]) > fabs(y[0] - y[1])) { calib.swapxy = 1; for (i = 0; i < 5; i++) { int t = x[i]; x[i] = y[i]; y[i] = t; } } /* get touch pad resolution to screen resolution ratio */ a1 = (double) (x[4] - x[0]) / (double) (cx[4] - cx[0]); a2 = (double) (x[3] - x[1]) / (double) (cx[3] - cx[1]); /* get the minimum pad position on the X-axis */ b1 = x[0] - a1 * cx[0]; b2 = x[1] - a2 * cx[1]; /* use the average ratio and average minimum position */ a = (a1 + a2) / 2.0; b = (b1 + b2) / 2.0; xerr = a * width / 2 + b - x[2]; if (fabs(xerr) > fabs(a * width * .01)) { fprintf(stderr, "Calibration problem: X axis error (%.2f) too high, try again\n", fabs(xerr)); goto err; } calib.minx = (int) (b + 0.5); calib.maxx = (int) (a * width + b + 0.5); /* get touch pad resolution to screen resolution ratio */ a1 = (double) (y[4] - y[0]) / (double) (cy[4] - cy[0]); a2 = (double) (y[3] - y[1]) / (double) (cy[3] - cy[1]); /* get the minimum pad position on the Y-axis */ b1 = y[0] - a1 * cy[0]; b2 = y[1] - a2 * cy[1]; /* use the average ratio and average minimum position */ a = (a1 + a2) / 2.0; b = (b1 + b2) / 2.0; yerr = a * height / 2 + b - y[2]; if (fabs(yerr) > fabs(a * height * 0.01)) { fprintf(stderr, "Calibration problem: Y axis error (%.2f) too high, try again\n", fabs(yerr)); goto err; } calib.miny = (int) (b + 0.5); calib.maxy = (int) (a * height + b + 0.5); XFlush(display); calib.resx = width; calib.resy = height; /* Send new values to the X server */ calib_data[0] = calib.minx; calib_data[1] = calib.maxx; calib_data[2] = calib.miny; calib_data[3] = calib.maxy; XChangeDeviceProperty(display, device, prop_calibration, XA_INTEGER, 32, PropModeReplace, (unsigned char *)calib_data, 4); swap = calib.swapxy; XChangeDeviceProperty(display, device, prop_swap, XA_INTEGER, 8, PropModeReplace, (unsigned char *)&swap, 1); XCloseDevice(display, device); XCloseDisplay(display); /* And print them for storage in wsconsctl.conf */ printf("mouse.scale=%d,%d,%d,%d,%d,%d,%d\n", calib.minx, calib.maxx, calib.miny, calib.maxy, calib.swapxy, calib.resx, calib.resy); return 0; err: draw_text(error_message, &errorColor); XFlush(display); sleep(2); goto calib; }
void WindowManager::init_internals(void) { ELOG("Starting window manager"); wm_conf = new WindowManagerConfig; app_starting = false; // defaults, in case world goes down wm_conf->title_active_color = fl_rgb(0,0,128); wm_conf->title_active_color_text = fl_rgb(255,255,255); wm_conf->title_normal_color = fl_rgb(192,192,192); wm_conf->title_normal_color_text = fl_rgb(0,0,128); wm_conf->title_label_align = FL_ALIGN_LEFT; wm_conf->title_height = 20; wm_conf->title_box_type = 0; wm_conf->frame_do_opaque = false; wm_conf->frame_animate = true; wm_conf->frame_animate_speed = 15; fl_open_display(); XSetErrorHandler(xerror_handler); wm_area.set(0, 0, Fl::w(), Fl::h()); read_configuration(); read_xset_configuration(); //register_protocols(); #ifdef _DEBUG InitAtoms(fl_display, atom_map); register_events(); #else InitAtoms(fl_display); #endif //cur = XCreateFontCursor(fl_display, XC_left_ptr); //XDefineCursor(fl_display, RootWindow(fl_display, fl_screen), cur); // load cursor cur = new CursorHandler; cur->load(X_CURSORS); cur->set_root_cursor(); sound_system = new SoundSystem(); sound_system->init(); sound_system->add(SOUND_MINIMIZE, "sounds/minimize.ogg"); sound_system->add(SOUND_MAXIMIZE, "sounds/maximize.ogg"); sound_system->add(SOUND_CLOSE, "sounds/close.ogg"); sound_system->add(SOUND_RESTORE, "sounds/restore.ogg"); sound_system->add(SOUND_SHADE, "sounds/shade.ogg"); // the world is starting here show(); register_protocols(); hint_stuff = new Hints; hint_stuff->icccm_set_iconsizes(this); init_clients(); Fl::add_handler(wm_event_handler); XSync(fl_display, 0); is_running = true; }
void input_init(running_machine &machine) override { int index; osd_printf_verbose("Lightgun: Begin initialization\n"); devmap_init(machine, &m_lightgun_map, SDLOPTION_LIGHTGUNINDEX, 8, "Lightgun mapping"); x11_event_manager::instance().initialize(); m_display = x11_event_manager::instance().display(); // Loop through all 8 possible devices for (index = 0; index < 8; index++) { XDeviceInfo *info; // Skip if the name is empty if (m_lightgun_map.map[index].name.length() == 0) continue; x11_lightgun_device *devinfo; std::string const &name = m_lightgun_map.map[index].name; char defname[512]; // Register and add the device devinfo = create_lightgun_device(machine, index); osd_printf_verbose("%i: %s\n", index, name.c_str()); // Find the device info associated with the name info = find_device_info(m_display, name.c_str(), 0); // If we couldn't find the device, skip if (info == nullptr) { osd_printf_verbose("Can't find device %s!\n", name.c_str()); continue; } //Grab device info and translate to stuff mame can use if (info->num_classes > 0) { // Add the lightgun buttons based on what we read add_lightgun_buttons((XAnyClassPtr)info->inputclassinfo, info->num_classes, devinfo); // Also, set the axix min/max ranges if we got them set_lightgun_axis_props((XAnyClassPtr)info->inputclassinfo, info->num_classes, devinfo); } // Add X and Y axis sprintf(defname, "X %s", devinfo->name()); devinfo->device()->add_item(defname, ITEM_ID_XAXIS, generic_axis_get_state, &devinfo->lightgun.lX); sprintf(defname, "Y %s", devinfo->name()); devinfo->device()->add_item(defname, ITEM_ID_YAXIS, generic_axis_get_state, &devinfo->lightgun.lY); // Save the device id devinfo->x11_state.deviceid = info->id; // Register this device to receive event notifications int events_registered = register_events(m_display, info, m_lightgun_map.map[index].name.c_str(), 0); osd_printf_verbose("Device %i: Registered %i events.\n", (int)info->id, events_registered); // register ourself to handle events from event manager int event_types[] = { motion_type, button_press_type, button_release_type }; osd_printf_verbose("Events types to register: motion:%d, press:%d, release:%d\n", motion_type, button_press_type, button_release_type); x11_event_manager::instance().subscribe(event_types, ARRAY_LENGTH(event_types), this); } osd_printf_verbose("Lightgun: End initialization\n"); }
int main(void) { fd_set descriptors; char socket_path[BUFSIZ]; int sock_fd, ret_fd, dpy_fd, sel, n; struct sockaddr_un sock_address; char msg[BUFSIZ] = {0}; char rsp[BUFSIZ] = {0}; xcb_generic_event_t *event; running = true; dpy = xcb_connect(NULL, &default_screen); if (xcb_connection_has_error(dpy)) die("error: cannot open display\n"); setup(); register_events(); dpy_fd = xcb_get_file_descriptor(dpy); char *sp = getenv(SOCKET_ENV_VAR); strncpy(socket_path, (sp == NULL ? DEFAULT_SOCKET_PATH : sp), sizeof(socket_path)); sock_address.sun_family = AF_UNIX; strncpy(sock_address.sun_path, socket_path, sizeof(sock_address.sun_path)); unlink(socket_path); sock_fd = socket(AF_UNIX, SOCK_STREAM, 0); if (sock_fd == -1) die("error: could not create socket\n"); bind(sock_fd, (struct sockaddr *) &sock_address, sizeof(sock_address)); listen(sock_fd, SOMAXCONN); sel = MAX(sock_fd, dpy_fd) + 1; load_settings(); run_autostart(); ewmh_update_wm_name(); update_root_dimensions(); while (running) { xcb_flush(dpy); FD_ZERO(&descriptors); FD_SET(sock_fd, &descriptors); FD_SET(dpy_fd, &descriptors); if (select(sel, &descriptors, NULL, NULL, NULL)) { if (FD_ISSET(sock_fd, &descriptors)) { ret_fd = accept(sock_fd, NULL, 0); if (ret_fd > 0 && (n = recv(ret_fd, msg, sizeof(msg), 0)) > 0) { msg[n] = '\0'; process_message(msg, rsp); send(ret_fd, rsp, strlen(rsp), 0); close(ret_fd); } } if (FD_ISSET(dpy_fd, &descriptors)) { while ((event = xcb_poll_for_event(dpy)) != NULL) { handle_event(event); free(event); } } } if (xcb_connection_has_error(dpy)) { die("connection has errors\n"); } } close(sock_fd); xcb_ewmh_connection_wipe(ewmh); free(ewmh); xcb_flush(dpy); xcb_disconnect(dpy); return 0; }
int main(int argc, char *argv[]) { if (argc == 2 && strcmp(argv[1], "-v") == 0) { printf("%s\n", VERSION); exit(EXIT_SUCCESS); } fd_set descriptors; char socket_path[MAXLEN]; int sock_fd, ret_fd, dpy_fd, sel, n; struct sockaddr_un sock_address; size_t rsplen = 0; char msg[BUFSIZ] = {0}; char rsp[BUFSIZ] = {0}; xcb_generic_event_t *event; running = true; dpy = xcb_connect(NULL, &default_screen); if (xcb_connection_has_error(dpy)) err("error: cannot open display\n"); setup(); register_events(); dpy_fd = xcb_get_file_descriptor(dpy); char *sp = getenv(SOCKET_ENV_VAR); strncpy(socket_path, (sp == NULL ? DEFAULT_SOCKET_PATH : sp), sizeof(socket_path)); sock_address.sun_family = AF_UNIX; strncpy(sock_address.sun_path, socket_path, sizeof(sock_address.sun_path)); unlink(socket_path); sock_fd = socket(AF_UNIX, SOCK_STREAM, 0); if (sock_fd == -1) err("error: could not create socket\n"); bind(sock_fd, (struct sockaddr *) &sock_address, sizeof(sock_address)); listen(sock_fd, SOMAXCONN); sel = MAX(sock_fd, dpy_fd) + 1; load_settings(); run_autostart(); grab_buttons(); ewmh_update_wm_name(); while (running) { xcb_flush(dpy); FD_ZERO(&descriptors); FD_SET(sock_fd, &descriptors); FD_SET(dpy_fd, &descriptors); if (select(sel, &descriptors, NULL, NULL, NULL)) { if (FD_ISSET(sock_fd, &descriptors)) { ret_fd = accept(sock_fd, NULL, 0); if (ret_fd > 0 && (n = recv(ret_fd, msg, sizeof(msg), 0)) > 0) { msg[n] = '\0'; process_message(msg, rsp); rsplen = strlen(rsp); if (rsp[rsplen - 1] == '\n') rsp[--rsplen] = '\0'; send(ret_fd, rsp, rsplen, 0); close(ret_fd); rsp[0] = '\0'; } } if (FD_ISSET(dpy_fd, &descriptors)) { while ((event = xcb_poll_for_event(dpy)) != NULL) { handle_event(event); free(event); } } } if (xcb_connection_has_error(dpy)) { err("connection has errors\n"); } } close(sock_fd); xcb_ewmh_connection_wipe(ewmh); free(ewmh); xcb_flush(dpy); xcb_disconnect(dpy); return 0; }
InvitationManager::InvitationManager() { register_events(); }