static gint target_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { BalloonEval *beval = (BalloonEval *)data; switch (event->type) { case GDK_ENTER_NOTIFY: pointer_event(beval, (int)event->crossing.x, (int)event->crossing.y, event->crossing.state); break; case GDK_MOTION_NOTIFY: if (event->motion.is_hint) { int x; int y; GdkModifierType state; /* * GDK_POINTER_MOTION_HINT_MASK is set, thus we cannot obtain * the coordinates from the GdkEventMotion struct directly. */ gdk_window_get_pointer(widget->window, &x, &y, &state); pointer_event(beval, x, y, (unsigned int)state); } else { pointer_event(beval, (int)event->motion.x, (int)event->motion.y, event->motion.state); } break; case GDK_LEAVE_NOTIFY: /* * Ignore LeaveNotify events that are not "normal". * Apparently we also get it when somebody else grabs focus. */ if (event->crossing.mode == GDK_CROSSING_NORMAL) cancelBalloon(beval); break; case GDK_BUTTON_PRESS: case GDK_SCROLL: cancelBalloon(beval); break; case GDK_KEY_PRESS: key_event(beval, event->key.keyval, TRUE); break; case GDK_KEY_RELEASE: key_event(beval, event->key.keyval, FALSE); break; default: break; } return FALSE; /* continue emission */ }
void basic_handler::handle_event(const SDL_Event& event) { //TODO this code path is never called? if (disp_ == NULL) { return; } switch (event.type) { case SDL_KEYDOWN: // If we're in a dialog we only want to handle items that are explicitly // handled by the executor. // If we're not in a dialog we can call the regular key event handler. if (!gui::in_dialog()) { key_event(*disp_, event.key,exec_); } else if (exec_ != NULL) { key_event_execute(*disp_, event.key,exec_); } break; case SDL_JOYBUTTONDOWN: if (!gui::in_dialog()) { jbutton_event(*disp_, event.jbutton,exec_); } else if (exec_ != NULL) { jbutton_event_execute(*disp_, event.jbutton,exec_); } break; case SDL_MOUSEBUTTONDOWN: if (!gui::in_dialog()) { mbutton_event(*disp_, event.button,exec_); } else if (exec_ != NULL) { mbutton_event_execute(*disp_, event.button,exec_); } break; } }
void basic_handler::handle_event(const SDL_Event& event) { switch (event.type) { case SDL_KEYDOWN: case SDL_KEYUP: // If we're in a dialog we only want to handle items that are explicitly // handled by the executor. // If we're not in a dialog we can call the regular key event handler. if (!gui::in_dialog()) { key_event(event,exec_); } else if (exec_ != nullptr) { event_execute(event,exec_); } break; case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: if (!gui::in_dialog()) { jbutton_event(event,exec_); } else if (exec_ != nullptr) { event_execute(event,exec_); } break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: if (!gui::in_dialog()) { mbutton_event(event,exec_); } else if (exec_ != nullptr) { event_execute(event,exec_); } break; } }
void lcl_OnyxLineEdit::mouseReleaseEvent(QMouseEvent * event) { event->accept(); emit getFocus(this); emit setCheckByMouse(this); QKeyEvent key_event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, "virtual"); QApplication::sendEvent(this, &key_event); }
int msg_recv_handle(int sockfd,char* buf) { int n,type; n = read(sockfd,buf,4); if(n==4) { getval(&type,buf,INT); SPICE_DEBUG("Got event:%d\n",type); switch(type) { case ANDROID_OVER: { android_send_task(ANDROID_TASK_OVER); g_main_loop_quit(android_mainloop); exit(1); return 1; } break; case ANDROID_KEY_PRESS: case ANDROID_KEY_RELEASE: n = read(sockfd,buf,4); if(n==4) { AndroidEventKey* key =(AndroidEventKey*)malloc(8); key->type = type; getval(&key->hardware_keycode,buf,INT); key_event(key); free(key); } else error("msg_recv error!\n"); break; case ANDROID_BUTTON_PRESS: case ANDROID_BUTTON_RELEASE: n = read(sockfd,buf,8); if(n==4) n += read(sockfd,buf+4,8); if(n==8) { AndroidEventButton* button =(AndroidEventButton*)malloc(12); button->type = type; getval(&button->x,buf,INT); getval(&button->y,buf+4,INT); button_event(button); free(button); } else error("msg_recv error!\n"); break; } } else error("msg_recv error!\n"); return 0; }
void basic_handler::handle_event(const SDL_Event& event) { if(event.type == SDL_KEYDOWN && disp_ != NULL) { //if we're in a dialog we only want to handle things that are explicitly handled //by the executor. If we're not in a dialog we can call the regular key event handler if(!gui::in_dialog()) { key_event(*disp_,event.key,exec_); } else if(exec_ != NULL) { key_event_execute(*disp_,event.key,exec_); } } }
void WindowView_Impl::on_key_up(const clan::InputEvent &e) { KeyEventType type = KeyEventType::release; Key key = decode_ic(e.id); int repeat_count = e.repeat_count; const std::string text = e.str; const Pointf pointer_pos = to_root_pos(e.mouse_pos); bool alt_down = e.alt; bool shift_down = e.shift; bool ctrl_down = e.ctrl; bool cmd_down = false; KeyEvent key_event(type, key, repeat_count, text, pointer_pos, alt_down, shift_down, ctrl_down, cmd_down); window_key_event(key_event); }
bool GboxInstance::HandleInputEvent(const pp::InputEvent &event) { bool ret = false; // handled? switch (event.GetType()) { case PP_INPUTEVENT_TYPE_KEYDOWN: case PP_INPUTEVENT_TYPE_KEYUP: case PP_INPUTEVENT_TYPE_CHAR: case PP_INPUTEVENT_TYPE_CONTEXTMENU: { pp::KeyboardInputEvent key_event(event); ret = HandleKeyboard(key_event); } break; case PP_INPUTEVENT_TYPE_MOUSEDOWN: case PP_INPUTEVENT_TYPE_MOUSEMOVE: case PP_INPUTEVENT_TYPE_MOUSEUP: case PP_INPUTEVENT_TYPE_MOUSEENTER: case PP_INPUTEVENT_TYPE_MOUSELEAVE: case PP_INPUTEVENT_TYPE_WHEEL: { pp::MouseInputEvent mouse_event(event); ret = HandleMouse(mouse_event); } break; case PP_INPUTEVENT_TYPE_UNDEFINED: case PP_INPUTEVENT_TYPE_RAWKEYDOWN: ret = false; default: break; } #if 1 if (!ret && sca() == 0x3) theLog.info("_Input Event: (%s a) et:%d handled:%d count:%d", kVersion, event.GetType(), ret, ++m_mc); #endif return ret; }
position Human_Player::calculate(double time) { key_event(event_); if (vel.x == 0) { if (keys[right]) { vel.x = 5.0; } else if (keys[left]) { vel.x = -5.0; } } if (tile_engine->does_bottom_collide(pos, size) == Tile_Engine::COLLIDES || player_engine->touch_bottom(this, players_collision) == Player::COLLIDE) { if (keys[up]) vel.y = -60.0; if (vel.x != 0){ if (keys[right]) vel.x = ( 2.0*time+vel.x > 30.0)? 30.0: 2.0*time+vel.x; if (keys[left]) vel.x = (-2.0*time+vel.x < -30.0)?-30.0:-2.0*time+vel.x; } if (keys[down]) vel.x = 0; vel.x=(vel.x > 0)?vel.x-0.8*time:vel.x+0.8*time; } else { vel.y = vel.y+15*time; } position new_pos = pos; if (vel.x != 0) { double new_x = pos.x + time*vel.x; new_pos.x = tile_engine->get_x_collision_move(pos.x, new_x, pos.y, size.x, size.y); if (new_pos.x != new_x) vel.x = 0; pos.x = new_pos.x; } if (vel.y != 0) { double new_y = pos.y + time*vel.y; new_pos.y = tile_engine->get_y_collision_move(pos.y, new_y, pos.x, size.x, size.y); if (new_pos.y != new_y) vel.y = 0; pos.y = new_pos.y; } return new_pos; }
/* ** Description ** This is the event handler that handles keyboard, mouse and timer events */ static void event_handler (VDI_Workstation * vwk) { Visual_Event visual_event; pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); /* Endless loop that will pump events from the visual and pass them over * to the right manager (mouse, keyboard) */ while (1) { VISUAL_GET_EVENT(vwk, &visual_event); switch(visual_event.type) { case Visual_Key_Press_Event : case Visual_Key_Repeat_Event : key_event( visual_event ); break; case Visual_Key_Release_Event : /* Do nothing */ break; case Visual_Mouse_Button_Event : if (vwk->butv != NULL) { vwk->butv (visual_event.mouse_button.buttons); } set_mouse_buttons( visual_event.mouse_button.buttons ); break; case Visual_Mouse_Move_Event : mouse_moved( visual_event.mouse_move.x, visual_event.mouse_move.y ); break; default: fprintf (stderr, "ovdisis: event.c: Unknown event 0x%x\n", visual_event.type); } } }
/* * Translates a Linux input event into a DirectFB input event. */ static int translate_event( struct input_event *levt, DFBInputEvent *devt ) { devt->flags = DIEF_TIMESTAMP; devt->timestamp = levt->time; switch (levt->type) { case EV_KEY: return key_event( levt, devt ); case EV_REL: return rel_event( levt, devt ); case EV_ABS: return abs_event( levt, devt ); default: ; } return 0; }
/** * \brief Get all keyboard events. */ void bear::input::keyboard::refresh_events() { SDL_Event e; m_key_events.clear(); // The range of events to process. const SDL_EventType event_min( SDL_TEXTINPUT ); const SDL_EventType event_max( event_min ); while ( SDL_PeepEvents(&e, 1, SDL_GETEVENT, event_min, event_max ) == 1 ) { const SDL_TextInputEvent* const evt ( reinterpret_cast<SDL_TextInputEvent*>(&e) ); const charset::string_type text( charset::convert_string( evt->text ) ); for ( std::wstring::const_iterator it( text.begin() ); it != text.end(); ++it ) m_key_events.push_back ( key_event ( key_event::key_event_character, key_info::from_char( *it ) ) ); } } // keyboard::refresh_events()
int w32_console_read_socket (struct terminal *terminal, struct input_event *hold_quit) { int nev, add; int isdead; block_input (); for (;;) { int nfnotify = handle_file_notifications (hold_quit); nev = fill_queue (0); if (nev <= 0) { /* If nev == -1, there was some kind of error If nev == 0 then no events were available so return. */ if (nfnotify) nev = 0; break; } while (nev > 0) { struct input_event inev; EVENT_INIT (inev); inev.kind = NO_EVENT; inev.arg = Qnil; switch (queue_ptr->EventType) { case KEY_EVENT: add = key_event (&queue_ptr->Event.KeyEvent, &inev, &isdead); if (add == -1) /* 95.7.25 by himi */ { queue_ptr--; add = 1; } if (add) kbd_buffer_store_event_hold (&inev, hold_quit); break; case MOUSE_EVENT: add = do_mouse_event (&queue_ptr->Event.MouseEvent, &inev); if (add) kbd_buffer_store_event_hold (&inev, hold_quit); break; case WINDOW_BUFFER_SIZE_EVENT: if (w32_use_full_screen_buffer) resize_event (&queue_ptr->Event.WindowBufferSizeEvent); break; case MENU_EVENT: case FOCUS_EVENT: /* Internal event types, ignored. */ break; } queue_ptr++; nev--; } } /* We don't get told about changes in the window size (only the buffer size, which we no longer care about), so we have to check it periodically. */ if (!w32_use_full_screen_buffer) maybe_generate_resize_event (); unblock_input (); return nev; }
event_result message_dispatcher::fire_on_key(app& the_app, AInputEvent *ie) { if (the_app.on_key(key_event(ie))) return event_result::handled; return event_result::unhandled; }
static void IN_HandleEvents( void ) { Uint16 *wtext = NULL; SDL_PumpEvents(); SDL_Event event; while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_KEYDOWN: key_event( &event.key, true ); // Emulate copy/paste #if defined( __APPLE__ ) #define KEYBOARD_COPY_PASTE_MODIFIER KMOD_GUI #else #define KEYBOARD_COPY_PASTE_MODIFIER KMOD_CTRL #endif if( event.key.keysym.sym == SDLK_c ) { if( event.key.keysym.mod & KEYBOARD_COPY_PASTE_MODIFIER ) { Key_CharEvent( KC_CTRLC, KC_CTRLC ); } } else if( event.key.keysym.sym == SDLK_v ) { if( event.key.keysym.mod & KEYBOARD_COPY_PASTE_MODIFIER ) { Key_CharEvent( KC_CTRLV, KC_CTRLV ); } } break; case SDL_KEYUP: key_event( &event.key, false ); break; case SDL_TEXTINPUT: // SDL_iconv_utf8_ucs2 uses "UCS-2-INTERNAL" as tocode and fails to convert text on Linux // where SDL_iconv uses system iconv. So we force needed encoding directly #if SDL_BYTEORDER == SDL_LIL_ENDIAN #define UCS_2_INTERNAL "UCS-2LE" #else #define UCS_2_INTERNAL "UCS-2BE" #endif wtext = (Uint16 *)SDL_iconv_string( UCS_2_INTERNAL, "UTF-8", event.text.text, SDL_strlen( event.text.text ) + 1 ); if( wtext ) { wchar_t charkey = wtext[0]; int key = ( charkey <= 255 ) ? charkey : 0; Key_CharEvent( key, charkey ); SDL_free( wtext ); } break; case SDL_MOUSEMOTION: mouse_motion_event( &event.motion ); break; case SDL_MOUSEBUTTONDOWN: mouse_button_event( &event.button, true ); break; case SDL_MOUSEBUTTONUP: mouse_button_event( &event.button, false ); break; case SDL_MOUSEWHEEL: mouse_wheel_event( &event.wheel ); break; case SDL_QUIT: Cbuf_ExecuteText( EXEC_NOW, "quit" ); break; case SDL_WINDOWEVENT: switch( event.window.event ) { case SDL_WINDOWEVENT_SHOWN: AppActivate( true ); break; case SDL_WINDOWEVENT_HIDDEN: AppActivate( false ); break; case SDL_WINDOWEVENT_CLOSE: break; case SDL_WINDOWEVENT_FOCUS_GAINED: input_focus = true; break; case SDL_WINDOWEVENT_FOCUS_LOST: input_focus = false; break; case SDL_WINDOWEVENT_MOVED: // FIXME: move this somewhere else Cvar_SetValue( "vid_xpos", event.window.data1 ); Cvar_SetValue( "vid_ypos", event.window.data2 ); vid_xpos->modified = false; vid_ypos->modified = false; break; } break; } } }
static gint target_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { BalloonEval *beval = (BalloonEval *)data; switch (event->type) { case GDK_ENTER_NOTIFY: pointer_event(beval, (int)event->crossing.x, (int)event->crossing.y, event->crossing.state); break; case GDK_MOTION_NOTIFY: if (event->motion.is_hint) { int x; int y; GdkModifierType state; /* * GDK_POINTER_MOTION_HINT_MASK is set, thus we cannot obtain * the coordinates from the GdkEventMotion struct directly. */ # if GTK_CHECK_VERSION(3,0,0) { GdkWindow * const win = gtk_widget_get_window(widget); GdkDisplay * const dpy = gdk_window_get_display(win); # if GTK_CHECK_VERSION(3,20,0) GdkSeat * const seat = gdk_display_get_default_seat(dpy); GdkDevice * const dev = gdk_seat_get_pointer(seat); # else GdkDeviceManager * const mngr = gdk_display_get_device_manager(dpy); GdkDevice * const dev = gdk_device_manager_get_client_pointer(mngr); # endif gdk_window_get_device_position(win, dev , &x, &y, &state); } # else gdk_window_get_pointer(widget->window, &x, &y, &state); # endif pointer_event(beval, x, y, (unsigned int)state); } else { pointer_event(beval, (int)event->motion.x, (int)event->motion.y, event->motion.state); } break; case GDK_LEAVE_NOTIFY: /* * Ignore LeaveNotify events that are not "normal". * Apparently we also get it when somebody else grabs focus. */ if (event->crossing.mode == GDK_CROSSING_NORMAL) cancelBalloon(beval); break; case GDK_BUTTON_PRESS: case GDK_SCROLL: cancelBalloon(beval); break; case GDK_KEY_PRESS: key_event(beval, event->key.keyval, TRUE); break; case GDK_KEY_RELEASE: key_event(beval, event->key.keyval, FALSE); break; default: break; } return FALSE; /* continue emission */ }
int main(int argc, char **argv) { int c; /* Alloc ttyclock */ ttyclock = malloc(sizeof(ttyclock_t)); ttyclock->option.date = True; /* Date format */ ttyclock->option.format = malloc(sizeof(char) * 100); /* Default date format */ strncpy(ttyclock->option.format, "%a %d %b %Y", 100); /* Default color */ ttyclock->option.color = COLOR_GREEN; /* COLOR_GREEN = 2 */ /* Default bottom pos */ ttyclock->option.bottom = False; /* Default delay */ ttyclock->option.delay = 40000000; /* 25FPS */ /* Default blink */ ttyclock->option.blink = False; while ((c = getopt(argc, argv, "tvsrcbihf:DBd:C:")) != -1) { switch(c) { case 'h': default: printf("usage : tty-clock [-scbtrvihDB] [-C [0-7]] [-f format] \n" " -s Show seconds \n" " -c Set the clock at the center of the terminal \n" " -b Set the clock at the bottom of the terminal \n" " -C [0-7] Set the clock color \n" " -t Set the hour in 12h format \n" " -r Do rebound the clock \n" " -f format Set the date format \n" " -v Show tty-clock version \n" " -i Show some info about tty-clock \n" " -h Show this page \n" " -d delay Set the delay between two redraws of the clock \n" " -D Hide date \n" " -B Enable blinking colon \n"); free(ttyclock); exit(EXIT_SUCCESS); break; case 'i': puts("TTY-Clock 2 © by Martin Duquesnoy ([email protected])"); free(ttyclock); free(ttyclock->option.format); exit(EXIT_SUCCESS); break; case 'v': puts("TTY-Clock 2 © devel version"); free(ttyclock); free(ttyclock->option.format); exit(EXIT_SUCCESS); break; case 's': ttyclock->option.second = True; break; case 'c': ttyclock->option.center = True; break; case 'b': ttyclock->option.bottom = True; break; case 'C': if(atoi(optarg) >= 0 && atoi(optarg) < 8) ttyclock->option.color = atoi(optarg); break; case 't': ttyclock->option.twelve = True; break; case 'r': ttyclock->option.rebound = True; break; case 'f': strncpy(ttyclock->option.format, optarg, 100); break; case 'd': if(atol(optarg) >= 0 && atol(optarg) < 1000000000) ttyclock->option.delay = atol(optarg); break; case 'D': ttyclock->option.date = False; break; case 'B': ttyclock->option.blink = True; break; } } init(); while(ttyclock->running) { clock_rebound(); update_hour(); draw_clock(); key_event(); } free(ttyclock); free(ttyclock->option.format); endwin(); return 0; }
int main(int argc, char **argv){ int c; /* Alloc ttyclock */ ttyclock = malloc(sizeof(ttyclock_t)); assert(ttyclock != NULL); memset(ttyclock, 0, sizeof(ttyclock_t)); ttyclock->option.date = True; /* Date format */ ttyclock->option.format = malloc(sizeof(char) * 100); /* Default date format */ strncpy(ttyclock->option.format, "%F", 100); /* Default color */ ttyclock->option.color = COLOR_RED; /* Default delay */ ttyclock->option.delay = 1; /* 1FPS */ ttyclock->option.nsdelay = 0; /* -0FPS */ ttyclock->option.blink = False; /* Never show seconds */ ttyclock->option.second = False; /* Hide the date */ ttyclock->option.date = False; atexit(cleanup); while ((c = getopt(argc, argv, "ivcbrhBxnC:d:T:a:")) != -1){ switch(c) { case 'h': default: print_usage(); exit(EXIT_SUCCESS); break; case 'i': puts("TTY-Clock 2 © by Martin Duquesnoy ([email protected]), Grey ([email protected])"); exit(EXIT_SUCCESS); break; case 'v': puts("TTY-Clock 2 © devel version"); exit(EXIT_SUCCESS); break; case 'c': ttyclock->option.center = True; break; case 'b': ttyclock->option.bold = True; break; case 'C': if(atoi(optarg) >= 0 && atoi(optarg) < 8) ttyclock->option.color = atoi(optarg); break; case 'r': ttyclock->option.rebound = True; break; case 'd': if(atol(optarg) >= 0 && atol(optarg) < 100) ttyclock->option.delay = atol(optarg); break; case 'B': ttyclock->option.blink = True; break; case 'a': if(atol(optarg) >= 0 && atol(optarg) < 1000000000) ttyclock->option.nsdelay = atol(optarg); break; case 'x': ttyclock->option.box = True; break; case 'T': { struct stat sbuf; if (stat(optarg, &sbuf) == -1) { fprintf(stderr, "tty-clock: error: couldn't stat '%s': %s.\n", optarg, strerror(errno)); exit(EXIT_FAILURE); } else if (!S_ISCHR(sbuf.st_mode)) { fprintf(stderr, "tty-clock: error: '%s' doesn't appear to be a character device.\n", optarg); exit(EXIT_FAILURE); } else { if (ttyclock->tty) free(ttyclock->tty); ttyclock->tty = strdup(optarg); }} break; case 'n': ttyclock->option.noquit = True; break; } } /* Set the default minutes to 25 */ start_minutes = DEFAULT_TIME; /* Check if short or long break */ if (optind < argc){ char *argument = argv[optind]; if (!strcmp(argument, "short")){ start_minutes = SHORT_BREAK; }else if (!strcmp(argument, "long")){ start_minutes = LONG_BREAK; }else{ printf("Command not recognized\n"); print_usage(); exit(EXIT_FAILURE); } } init(); attron(A_BLINK); while(ttyclock->running){ clock_rebound(); update_hour(); draw_clock(); key_event(); } endwin(); return 0; }
int w32_console_read_socket (struct terminal *terminal, int expected, struct input_event *hold_quit) { BOOL no_events = TRUE; int nev, ret = 0, add; int isdead; if (interrupt_input_blocked) { interrupt_input_pending = 1; return -1; } interrupt_input_pending = 0; BLOCK_INPUT; for (;;) { nev = fill_queue (0); if (nev <= 0) { /* If nev == -1, there was some kind of error If nev == 0 then waitp must be zero and no events were available so return. */ UNBLOCK_INPUT; return nev; } while (nev > 0) { struct input_event inev; EVENT_INIT (inev); inev.kind = NO_EVENT; inev.arg = Qnil; switch (queue_ptr->EventType) { case KEY_EVENT: add = key_event (&queue_ptr->Event.KeyEvent, &inev, &isdead); if (add == -1) /* 95.7.25 by himi */ { queue_ptr--; add = 1; } if (add) kbd_buffer_store_event_hold (&inev, hold_quit); break; case MOUSE_EVENT: add = do_mouse_event (&queue_ptr->Event.MouseEvent, &inev); if (add) kbd_buffer_store_event_hold (&inev, hold_quit); break; case WINDOW_BUFFER_SIZE_EVENT: if (w32_use_full_screen_buffer) resize_event (&queue_ptr->Event.WindowBufferSizeEvent); break; case MENU_EVENT: case FOCUS_EVENT: /* Internal event types, ignored. */ break; } queue_ptr++; nev--; } if (ret > 0 || expected == 0) break; } /* We don't get told about changes in the window size (only the buffer size, which we no longer care about), so we have to check it periodically. */ if (!w32_use_full_screen_buffer) maybe_generate_resize_event (); UNBLOCK_INPUT; return ret; }
static void * x_thread_main (void *closure) { x_global_t *xg = closure; XEvent event; struct pollfd fds[2]; int timeout; sigset_t mask; sigemptyset (&mask); sigaddset (&mask, SIGALRM); sigaddset (&mask, SIGIO); sigaddset (&mask, SIGCHLD); sigaddset (&mask, SIGINT); pthread_sigmask (SIG_BLOCK, &mask, NULL); fds[0].fd = ConnectionNumber (xg->dpy); fds[0].events = POLLIN; fds[1].fd = xg->pipe[0]; fds[1].events = POLLIN; while (xg->running) { while (XPending (xg->dpy)) { XNextEvent (xg->dpy, &event); switch (event.type) { case ConfigureNotify: configure_event (xg, &event.xconfigure); break; case Expose: expose_event (xg, &event.xexpose); break; case MotionNotify: motion_notify_event (xg, &event.xmotion); break; case ButtonPress: case ButtonRelease: button_event (xg, &event.xbutton); break; case KeyPress: case KeyRelease: key_event (xg, &event.xkey); break; case ClientMessage: client_message_event (xg, &event.xclient); break; case FocusIn: case FocusOut: focus_change_event (xg, &event.xfocus); break; } } timeout = -1; while (xg->repaint) { int when = now (); timeout = xg->repaint->when - when; if (timeout > 0) break; timeout = -1; repaint_timeout (xg, when); } poll (fds, 2, timeout); if (fds[1].revents & POLLIN) { char stuffed[128]; read (fds[1].fd, stuffed, sizeof (stuffed)); } } close (xg->pipe[0]); close (xg->pipe[1]); XCloseDisplay (xg->dpy); free (xg); return 0; }
int main(int argc, char **argv) { int c; /* Alloc ttyclock */ ttyclock = malloc(sizeof(ttyclock_t)); assert(ttyclock != NULL); memset(ttyclock, 0, sizeof(ttyclock_t)); /* Date format */ ttyclock->option.format = malloc(sizeof(char) * 100); /* Default date format */ strncpy(ttyclock->option.format, "%F", 100); /* Default color */ ttyclock->option.color = COLOR_GREEN; /* COLOR_GREEN = 2 */ /* Default delay */ ttyclock->option.delay = 40000000; /* 25FPS */ atexit(cleanup); while ((c = getopt(argc, argv, "tT:nvsSrcihbf:d:C:")) != -1) { switch(c) { case 'h': default: printf("usage : tty-clock [-sSbctrnvih] [-C [0-7]] [-f format] [-d delay] [-T tty] \n" " -s Show seconds \n" " -S Screensaver mode \n" " -b Show box \n" " -c Set the clock at the center of the terminal \n" " -C [0-7] Set the clock color \n" " -t Set the hour in 12h format \n" " -T tty Display the clock on the specified terminal \n" " -r Do rebound the clock \n" " -f format Set the date format \n" " -n Don't quit on keypress \n" " -v Show tty-clock version \n" " -i Show some info about tty-clock \n" " -h Show this page \n" " -d delay Set the delay between two redraws of the clock \n"); exit(EXIT_SUCCESS); break; case 'i': puts("TTY-Clock 2 © by Martin Duquesnoy ([email protected])"); exit(EXIT_SUCCESS); break; case 'v': puts("TTY-Clock 2 © devel version"); exit(EXIT_SUCCESS); break; case 's': ttyclock->option.second = True; break; case 'S': ttyclock->option.screensaver = True; break; case 'c': ttyclock->option.center = True; break; case 'C': if(atoi(optarg) >= 0 && atoi(optarg) < 8) ttyclock->option.color = atoi(optarg); break; case 't': ttyclock->option.twelve = True; break; case 'r': ttyclock->option.rebound = True; break; case 'f': strncpy(ttyclock->option.format, optarg, 100); break; case 'd': if(atol(optarg) >= 0 && atol(optarg) < 1000000000) ttyclock->option.delay = atol(optarg); break; case 'b': ttyclock->option.box = True; break; case 'T': { struct stat sbuf; if (stat(optarg, &sbuf) == -1) { fprintf(stderr, "tty-clock: error: couldn't stat '%s': %s.\n", optarg, strerror(errno)); exit(EXIT_FAILURE); } else if (!S_ISCHR(sbuf.st_mode)) { fprintf(stderr, "tty-clock: error: '%s' doesn't appear to be a character device.\n", optarg); exit(EXIT_FAILURE); } else { if (ttyclock->tty) free(ttyclock->tty); ttyclock->tty = strdup(optarg); } } break; case 'n': ttyclock->option.noquit = True; break; } } init(); while(ttyclock->running) { clock_rebound(); update_hour(); draw_clock(); key_event(); } endwin(); return 0; }