📄 bcwindow.c
字号:
//if(!repeat_buffer) //{ repeat_timer.get_difference(¤t_repeat);//printf("current_repeat.tv_sec %ld current_repeat.tv_usec %ld\n", current_repeat.tv_sec, current_repeat.tv_usec); if(current_repeat.tv_sec < 1 && current_repeat.tv_usec < repeat) { delay_duration.tv_sec = 0; delay_duration.tv_usec = repeat - current_repeat.tv_usec; select(0, NULL, NULL, NULL, &delay_duration); } //}// dispatch repeat if there is no waiting event if(!XPending(display)) { repeat_timer.update(); repeat_buffer = 0; repeat_dispatch(); } }// quit if repeat resulted in a set_done if(done) return 1;// zero all flags key_pressed = 0; button_pressed = 0; ctrl_mask = 0; shift_mask = 0; cursorleft = 0; resized = 0; event_win = 0; double_click = 0; // if an event is waiting, get it, otherwise// wait for next event if there is no repeat and no motion history if(XPending(display) || (!repeat && !motion_buffer)) {// test for skipped repeat event if there is an event waiting if(repeat) repeat_buffer = 1; XNextEvent(display, &report);//printf("XNextEvent(display, &report); %d\n", report.type);// lock out anyone who tries to delete a window beyond this point// deletions between XNextEvent and this get through lock_window(); } else if(motion_buffer) {// handle buffered motion events if there is no waiting event lock_window();// ctrl key down if(report.xkey.state & ControlMask) ctrl_mask = 1;// shift key down if(report.xkey.state & ShiftMask) shift_mask = 1; dispatch_motion_event_main(); }// ctrl key down if(report.xkey.state & ControlMask) ctrl_mask = 1;// shift key down if(report.xkey.state & ShiftMask) shift_mask = 1; // need cursor position for button events if(report.type == ButtonPress || report.type == ButtonRelease) { XTranslateCoordinates(display, report.xany.window, win, report.xbutton.x, report.xbutton.y, &button_x, &button_y, &tempwin); }// dispatch the event switch(report.type) {// window exposed case Expose://printf("Expose\n"); event_win = report.xany.window; expose_event_dispatch(); break; // window closed case ClientMessage:// clear the motion buffer since this can clear the window if(motion_buffer) { dispatch_motion_event_main(); } { XClientMessageEvent *ptr; ptr = (XClientMessageEvent*)&report; if(ptr->message_type == ProtoXAtom && ptr->data.l[0] == DelWinXAtom) { close_event(); } } break; case ButtonPress://printf("ButtonPress\n");// get location information cursor_x = button_x; cursor_y = button_y;// get button information button_pressed = report.xbutton.button; // get time information event_win = report.xany.window; button_down = 1; button_time1 = button_time2; button_time2 = report.xbutton.time; if(button_time2 - button_time1 < 300) double_click = 1; else double_click = 0; if(active_menubar) active_menubar->button_press_dispatch(); else if(active_popup_menu) active_popup_menu->button_press_dispatch(); else button_press_dispatch(); break; case ButtonRelease://printf("ButtonRelease\n");// get location information cursor_x = button_x; cursor_y = button_y;//printf("cursor_x %d cursor_y %d active_menubar %x active_popup_menu %x \n", cursor_x, cursor_y, active_menubar, active_popup_menu); event_win = report.xany.window; button_just_released++; // X generates cursor leave events after button release button_down = 0; if(active_menubar) active_menubar->button_release_dispatch(); else if(active_popup_menu) active_popup_menu->button_release_dispatch(); else button_release_dispatch(); break; case MotionNotify://printf("MotionNotify\n");// window can get destroyed after the button release and the motion notify event// buffer it if it's the first motion from any window if(!motion_buffer) { store_motion_event(&report); } else// buffer it if it's a subsequent motion from the same window if(motion_buffer_win == report.xany.window) { store_motion_event(&report); } else// dispatch it if it's a subsequent motion from a different window { dispatch_motion_event_main(); // arm buffer with new motion event store_motion_event(&report); } break; case ConfigureNotify: if(report.xany.window == win && (report.xconfigure.width != w || report.xconfigure.height != h) && (report.xconfigure.width != last_w || report.xconfigure.height != last_h)) {//printf("ConfigureNotify %d %d %d %d\n", w, h, report.xconfigure.width, report.xconfigure.height);//sleep(1); last_w = w = report.xconfigure.width; last_h = h = report.xconfigure.height; resized = 1;// only give to user here resize_event(w, h);// send to all objects resize_event_dispatch(); } break; case KeyPress://printf("KeyPress\n"); static KeySym keysym; static char keys_return[2]; keys_return[0] = '\0'; XLookupString ((XKeyEvent*)&report, keys_return, 1, &keysym, 0);//printf("keysym %x\n", keysym);// block out control keys if(keysym > 0xffe0){ break; } switch(keysym){// block out some keys case XK_Alt_L: key_pressed = 0; break; case XK_Alt_R: key_pressed = 0; break; case XK_Shift_L: key_pressed = 0; break; case XK_Shift_R: key_pressed = 0; break; case XK_Control_L: key_pressed = 0; break; case XK_Control_R: key_pressed = 0; break; // translate key codes case XK_Up: key_pressed = UP; break; case XK_Down: key_pressed = DOWN; break; case XK_Left: key_pressed = LEFT; break; case XK_Right: key_pressed = RIGHT; break; case XK_Next: key_pressed = PGDN; break; case XK_Prior: key_pressed = PGUP; break; case XK_BackSpace: key_pressed = BACKSPACE; break; case XK_Escape: key_pressed = ESC; break; case XK_Tab: key_pressed = TAB; break; case XK_underscore: key_pressed = '_'; break; case XK_asciitilde: key_pressed = '~'; break; // number pad case XK_KP_Enter: key_pressed = KPENTER; break; case XK_KP_Add: key_pressed = KPPLUS; break; case XK_KP_End: key_pressed = KP1; break; case XK_KP_Down: key_pressed = KP2; break; case XK_KP_Page_Down: key_pressed = KP3; break; case XK_KP_Left: key_pressed = KP4; break; case XK_KP_Begin: key_pressed = KP5; break; case XK_KP_Right: key_pressed = KP6; break; case XK_KP_Insert: key_pressed = KPINS; break; case XK_KP_Delete: key_pressed = KPDEL; break; default: key_pressed = keys_return[0]; break; }// dispatch keypress until trapped keypress_event_dispatch(); // give to user after everyone else has trapped it if(key_pressed && enabled) keypress_event(); break; case FocusOut: cursor_x = cursor_y = -1; cursor_left_dispatch(); break; case LeaveNotify://printf("LeaveNotify\n"); event_win = report.xany.window; if(report.xcrossing.focus) {// button release dispatches leavenotify cursor_x = report.xcrossing.x; cursor_y = report.xcrossing.y; } else {// cursor position is reported inside tool when crossing to a higher window cursor_x = cursor_y = -1; }//printf("%d %d focus %d\n", cursor_x, cursor_y, report.xcrossing.focus);// dispatch to subwindows cursor_left_dispatch(); break; } unlock_window(); report.type = 0; // clear this report in case next event is a repeat or motion buffer}// ================================== motion eventsBC_Window::store_motion_event(XEvent *report){ static Window tempwin;// only store if the motion wasn't in the last deleted window if(last_deleted_window != report->xany.window) { motion_buffer = 1; XTranslateCoordinates(display, report->xany.window, win, report->xmotion.x, report->xmotion.y, &motion_buffer_x, &motion_buffer_y, &tempwin); motion_buffer_win = report->xany.window; }}BC_Window::dispatch_motion_event_main(){ event_win = motion_buffer_win; cursor_x = motion_buffer_x; cursor_y = motion_buffer_y; motion_buffer = 0;//printf("BC_Window::dispatch_motion_event_main %d %d\n", cursor_x, cursor_y); if(active_menubar) active_menubar->motion_event_dispatch(); else if(active_popup_menu) active_popup_menu->motion_event_dispatch(); else motion_event_dispatch();}// ===================================== configurationBC_Window::set_last_deleted(Window win) { last_deleted_window = win; }BC_Window::shift_down(){ return shift_mask; };BC_Window::ctrl_down(){ return ctrl_mask; };BC_Window::lock_window() { XLockDisplay(display); }BC_Window::unlock_window() { XUnlockDisplay(display); }BC_Window::show_window() { XMapWindow(display, win); hidden = 0; XFlush(display); }BC_Window::hide_window() { XUnmapWindow(display, win); hidden = 1; XFlush(display); }// flush out all the eventsBC_Window::window_reset(){ XEvent report; //while(XPending(display)) XNextEvent(display, &report); //flash();}// ================================== event handlersBC_Window::set_repeat(long duration) // signal the event handler to repeat{ repeat = duration; repeat_timer.update(); repeat_buffer = 0;}BC_Window::unset_repeat() { repeat = 0; repeat_buffer = 0;}BC_Window::set_done(int return_value){ XExposeEvent report; report.type = Expose; done = 1; XSendEvent(display, win, 0, 0, (XEvent *)&report); this->return_value = return_value; XFlush(display);}BC_Window::set_title(char *title) { XSetStandardProperties(display, win, title, title, None, 0, 0, 0); XFlush(display);}BC_Window::to_clipboard(char *data) { XStoreBytes(display, data, strlen(data)); }BC_Window::clipboard_len(){ char *data2; int len; data2 = XFetchBytes(display, &len); XFree(data2); return len;}BC_Window::from_clipboard(char *data){ char *data2; int len, i; data2 = XFetchBytes(display, &len); for(i = 0; i < len; i++) data[i] = data2[i]; data[i] = 0; XFree(data2);}// ========================= cycle every text box in every subwindowBC_Window::cycle_textboxes(){ int result = 0; BC_Tool *tool = 0; find_next_textbox(tool, &result); if(result == 0) {// no active textbox found return 0; } if(result == 1) {// no next textbox found find_first_textbox(tool); }// activate the tool if(tool) tool->activate();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -