/* cursor_to_input: move the cursor to the input line, if not there already */ void cursor_to_input(void) { if (screen_get_alive(get_current_screen()) && is_cursor_in_display()) { ScreenInputData *inputdata = screen_get_inputdata(get_current_screen()); term_move_cursor(inputdata->cursor_x, inputdata->cursor_y); Debug(DB_CURSOR, "cursor_to_input: moving cursor to input for screen %d", screen_get_screennum(get_current_screen())); cursor_not_in_display(); term_flush(); } }
/** * handle_mouse_pos(GLFWwindow * screen, double x, double y) * * @brief * @param screen * @param x * @param y * @return void */ void handle_mouse_pos(GLFWwindow * screen, double x, double y) { setcurrentscreen(getscreenid(screen)); widget_move((int16)x,(int16)y); widget_set_mouse_pos((int16)x,(int16)y); if(get_current_screen()->id == 0 && get_mapeditor_state() == TRUE && get_current_screen()->ui.screen.clicked == 1) { ingame_screen_press(NULL,get_current_screen()->ui.screen.button,get_current_screen()->ui.screen.clicked); } resetcurrentscreen(); #if(DEBUG) printf(" x = %i\n", x); printf(" Y = %i\n", y); #endif }
/* * term_resize: gets the terminal height and width. Trys to get the info * from the tty driver about size, if it can't... uses the termcap values. If * the terminal size has changed since last time term_resize() has been * called, 1 is returned. If it is unchanged, 0 is returned. */ int term_resize(void) { int new_li = li, new_co = co; /* * if we're not the main screen, we've probably arrived here via * the wserv message path, and we should have already setup the * values of "li" and "co". */ if (is_main_screen(get_current_screen())) { #ifdef TIOCGWINSZ struct winsize window; if (ioctl(tty_des, TIOCGWINSZ, &window) == 0) { new_li = window.ws_row; new_co = window.ws_col; } #endif /* TIOCGWINSZ */ #ifndef TERM_USE_LAST_COLUMN new_co--; #endif } return screen_set_size(new_li, new_co); }
void ScreenManager::update(float delta, const std::vector<Input::Event>& events) { ScreenManagerUpdatePackage package(this, get_current_screen(), delta, events); ScreenManagerUpdatePackage* pp = &package; ceu_out_go(&CEUapp, CEU_IN_SCREEN_MANAGER_UPDATE, &pp); }
static void input_do_replace_prompt(u_char *newprompt) { ScreenInputData *inputdata = screen_get_inputdata(get_current_screen()); ScreenInputBufferData* bufdata = &inputdata->buffer; u_char* buf = bufdata->buf; unsigned oldlen = bufdata->minpos; unsigned newlen = my_strlen(newprompt); unsigned max = sizeof(bufdata->buf); unsigned saved_len = max - (oldlen > newlen ? oldlen : newlen); memmove(buf+newlen, buf+oldlen, saved_len); memcpy(buf, newprompt, newlen); buf[max-1] = '\0'; /* prevent dragons */ bufdata->minpos = newlen; bufdata->pos = bufdata->pos - oldlen + newlen; if (bufdata->pos < newlen) bufdata->pos = newlen; }
void ScreenManager::resize(const Size& size) { display_gc->set_rect(Rect(Vector2i(0, 0), size)); // The other screens will get resized when they become the current screen get_current_screen()->resize(size); }
void term_beep(void) { tputs_x(BL); Screen *screen = get_current_screen(); fflush(screen ? screen_get_fpout(screen) : stdout); }
static void input_do_set_cursor_pos(unsigned pos) { ScreenInputData *inputdata = screen_get_inputdata(get_current_screen()); inputdata->buffer.pos = pos; update_input(UPDATE_JUST_CURSOR); }
Point2 OS_X11::get_window_position() const { int x,y; Window child; XTranslateCoordinates( x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child); int screen = get_current_screen(); Point2i screen_position = get_screen_position(screen); return Point2i(x-screen_position.x, y-screen_position.y); }
static void input_do_delete_raw(int n, int do_save_cut) { ScreenInputData *inputdata = screen_get_inputdata(get_current_screen()); u_char* buf = inputdata->buffer.buf; unsigned pos = inputdata->buffer.pos; unsigned max = sizeof(inputdata->buffer.buf); /* If n>0, deletes from front * if n<0, deletes from back & moves cursor */ if (n < 0) { unsigned limit = inputdata->buffer.minpos; /* Number of bytes LEFT from the cursor (prompt excluding) */ unsigned oldbytes = pos-limit; unsigned erasebytes = -n; /* Don't delete more than we can */ if (erasebytes > oldbytes) erasebytes = oldbytes; /* Move cursor backward */ pos -= erasebytes; input_do_set_cursor_pos(pos); /* Then delete from forward */ n = erasebytes; } if (n > 0) { unsigned oldbytes = max-pos; unsigned erasebytes = n > oldbytes ? oldbytes : n; unsigned newbytes = oldbytes - erasebytes; if (do_save_cut) { if (cut_buffer) new_free(&cut_buffer); cut_buffer = new_malloc(erasebytes+1); memcpy(cut_buffer, buf+pos, erasebytes); cut_buffer[erasebytes] = '\0'; } memmove(buf+pos, buf+pos+erasebytes, newbytes); buf[pos+newbytes] = '\0'; } /* Now update the right side from cursor */ update_input(UPDATE_FROM_CURSOR); }
void OS_X11::set_window_position(const Point2& p_position) { // Using EWMH -- Extended Window Manager Hints // to get the size of the decoration #if 0 Atom property = XInternAtom(x11_display,"_NET_FRAME_EXTENTS", True); Atom type; int format; unsigned long len; unsigned long remaining; unsigned char *data = NULL; int result; result = XGetWindowProperty( x11_display, x11_window, property, 0, 32, False, AnyPropertyType, &type, &format, &len, &remaining, &data ); long left = 0L; long top = 0L; if( result == Success ) { long *extends = (long *) data; left = extends[0]; top = extends[2]; XFree(data); } int screen = get_current_screen(); Point2i screen_position = get_screen_position(screen); left -= screen_position.x; top -= screen_position.y; XMoveWindow(x11_display,x11_window,p_position.x - left,p_position.y - top); #else XMoveWindow(x11_display,x11_window,p_position.x,p_position.y); #endif }
static void input_do_delete_chars(int n, int do_save_cut) { ScreenInputData *inputdata = screen_get_inputdata(get_current_screen()); u_char* buf = inputdata->buffer.buf; unsigned pos = inputdata->buffer.pos; /* The usage of this function is identical to input_do_delete_raw(), * but instead of bytes, n means the number of characters. * Since characters may consist of 1-4 bytes, this * function converts the number to bytes and then * calls input_do_delete_raw(). */ if (n > 0) { int bytes; for (bytes = 0; buf[pos] != '\0' && n > 0; --n) { unsigned length = calc_unival_length(buf+pos); bytes += length; pos += length; } input_do_delete_raw(bytes, do_save_cut); } else if (n < 0) { unsigned limit = inputdata->buffer.minpos; int bytes; for (bytes = 0; n < 0 && pos > limit; ++n) { /* Go back until we reach a beginning of a character */ for (;;) { unsigned length = calc_unival_length(buf + --pos); if (length) { bytes += length; break; } /* But don't go more than we're allowed to */ if (pos == limit) break; } } input_do_delete_raw(-bytes, do_save_cut); } }
void OS_X11::set_current_screen(int p_screen) { int count = get_screen_count(); if(p_screen >= count) return; if( current_videomode.fullscreen ) { Point2i position = get_screen_position(p_screen); Size2i size = get_screen_size(p_screen); XMoveResizeWindow(x11_display, x11_window, position.x, position.y, size.x, size.y); } else { if( p_screen != get_current_screen() ) { Point2i position = get_screen_position(p_screen); XMoveWindow(x11_display, x11_window, position.x, position.y); } } }
static int input_is_password_prompt(void) { ScreenInputData *inputdata = screen_get_inputdata(get_current_screen()); u_char* buf = inputdata->buffer.buf; unsigned limit = inputdata->buffer.minpos; if (limit < 9) return 0; /* If the prompt ends with "Password:"******"Password:"******"Operator Password:"******"Server Password:"******"Password:"), 9) == 0; }
static char input_check_resized(void) { ScreenInputData *inputdata = screen_get_inputdata(get_current_screen()); int new_li = get_li(); int new_co = get_co(); if (inputdata->old_li == new_li && inputdata->old_co == new_co) return 0; /* resized? Keep it simple and reset everything */ inputdata->cursor_x = 0; inputdata->cursor_y = new_li - 1; inputdata->old_li = new_li; inputdata->old_co = new_co; inputdata->zone = new_co; if (inputdata->zone > WIDTH) inputdata->zone -= WIDTH; return 1; }
static void input_do_insert_raw(u_char* source) { ScreenInputData *inputdata = screen_get_inputdata(get_current_screen()); u_char* buf = inputdata->buffer.buf; unsigned pos = inputdata->buffer.pos; unsigned max = sizeof(inputdata->buffer.buf); unsigned inslen = my_strlen(source); /* This function inserts the given substring of bytes * to the input line at the current editing position. * Cursor is moved to point to the end of the substring. */ if (pos + inslen > max) { inslen = max - pos; } /* Move the tail out of way */ memmove(buf + pos + inslen, buf + pos, max - pos - inslen); /* Then put the substring in */ memcpy(buf + pos, source, inslen); /* Ensure the buffer is terminated */ buf[max - 1] = '\0'; pos += inslen; if (pos > max) pos = max; /* Update the screen from the old cursor position */ update_input(UPDATE_FROM_CURSOR); /* Then place the cursor correctly */ input_do_set_cursor_pos(pos); }
static char input_do_check_prompt(int update) { ScreenInputData *inputdata = screen_get_inputdata(get_current_screen()); u_char *prompt; u_char *ptr; char changed = 0; int free_it = 1; unsigned len; int args_used; /* unused */ if (update == NO_UPDATE) return changed; prompt = prompt_current_prompt(); if (!prompt) prompt = input_prompt ? input_prompt : empty_string(); if (is_process(get_target_by_refnum(0))) { ptr = get_prompt_by_refnum(0); free_it = 0; } else ptr = expand_alias(NULL, prompt, empty_string(), &args_used, NULL); len = my_strlen(ptr); if (my_strncmp(ptr, inputdata->buffer.buf, len) || !len) { input_do_replace_prompt(ptr); changed = 1; } if (free_it) new_free(&ptr); return changed; }
Bool ReloadASEnvironment (ASImageManager ** old_imageman, ASFontManager ** old_fontman, BaseConfig ** config_return, Bool flush_images, Bool support_shared_images) { char *old_pixmap_path = NULL; char *old_font_path = NULL; char *configfile = NULL; BaseConfig *config = NULL; ASEnvironment *e = NULL; ScreenInfo *scr = get_current_screen (); if (Environment != NULL) { old_pixmap_path = Environment->pixmap_path; Environment->pixmap_path = NULL; old_font_path = Environment->font_path; Environment->font_path = NULL; } configfile = Session->overriding_file; if (configfile == NULL) configfile = make_session_file (Session, BASE_FILE, False /* no longer use #bpp in filenames */ ); if (configfile != NULL) { config = ParseBaseOptions (configfile, MyName); if (config != NULL) show_progress ("BASE configuration loaded from \"%s\" ...", configfile); else show_progress ("BASE could not be loaded from \"%s\" ...", configfile); if (configfile != Session->overriding_file) free (configfile); } else show_warning ("BASE configuration file cannot be found"); if (config == NULL) { if (Environment != NULL) { Environment->pixmap_path = old_pixmap_path; Environment->font_path = old_font_path; return False; } /* otherwise we should use default values - Environment should never be NULL */ Environment = make_default_environment (); } else { BaseConfig2ASEnvironment (config, &Environment); if (config_return) *config_return = config; else DestroyBaseConfig (config); } e = Environment; /* Save base filename to pass to modules */ if (mystrcmp (old_pixmap_path, e->pixmap_path) == 0 || (e->pixmap_path != NULL && scr->image_manager == NULL) || flush_images) { reload_screen_image_manager (scr, old_imageman); } if (old_pixmap_path && old_pixmap_path != e->pixmap_path) free (old_pixmap_path); if (mystrcmp (old_font_path, e->font_path) == 0 || (e->font_path != NULL && scr->font_manager == NULL)) { if (old_fontman) { *old_fontman = scr->font_manager; } else if (scr->font_manager) destroy_font_manager (scr->font_manager, False); scr->font_manager = create_font_manager (dpy, e->font_path, NULL); set_xml_font_manager (scr->font_manager); show_progress ("Font Path changed to \"%s\" ...", e->font_path ? e->font_path : ""); } if (old_font_path && old_font_path != e->font_path) free (old_font_path); if (e->desk_pages_h > 0) { if (e->desk_pages_h <= 100) scr->VxMax = (e->desk_pages_h - 1) * scr->MyDisplayWidth; else { scr->VxMax = MAX (e->desk_pages_h, scr->MyDisplayWidth) - scr->MyDisplayWidth; e->desk_pages_h = (e->desk_pages_h + scr->MyDisplayWidth - 1) / scr->MyDisplayWidth; } } else scr->VxMax = 0; if (e->desk_pages_v > 0) { if (e->desk_pages_v <= 100) scr->VyMax = (e->desk_pages_v - 1) * scr->MyDisplayHeight; else { scr->VyMax = MAX (e->desk_pages_v, scr->MyDisplayHeight) - scr->MyDisplayHeight; e->desk_pages_v = (e->desk_pages_v + scr->MyDisplayHeight - 1) / scr->MyDisplayHeight; } } else scr->VyMax = 0; scr->VScale = e->desk_scale; if (scr->VScale <= 1) scr->VScale = 2; else if (scr->VScale >= scr->MyDisplayHeight / 2) scr->VScale = scr->MyDisplayHeight / 2; #ifdef XSHMIMAGE if (support_shared_images) { if (get_flags (e->flags, ASE_NoSharedMemory)) disable_shmem_images (); else enable_shmem_images (); } SHOW_CHECKPOINT; #endif return (config != NULL); }
void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { last_button_state=0; xmbstring=NULL; event_id=0; x11_window=0; last_click_ms=0; args=OS::get_singleton()->get_cmdline_args(); current_videomode=p_desired; main_loop=NULL; last_timestamp=0; last_mouse_pos_valid=false; last_keyrelease_time=0; if (get_render_thread_mode()==RENDER_SEPARATE_THREAD) { XInitThreads(); } /** XLIB INITIALIZATION **/ x11_display = XOpenDisplay(NULL); char * modifiers = XSetLocaleModifiers ("@im=none"); ERR_FAIL_COND( modifiers == NULL ); xim = XOpenIM (x11_display, NULL, NULL, NULL); if (xim == NULL) { WARN_PRINT("XOpenIM failed"); xim_style=0L; } else { ::XIMStyles *xim_styles=NULL; xim_style=0L; char *imvalret=NULL; imvalret = XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL); if (imvalret != NULL || xim_styles == NULL) { fprintf (stderr, "Input method doesn't support any styles\n"); } if (xim_styles) { xim_style = 0L; for (int i=0;i<xim_styles->count_styles;i++) { if (xim_styles->supported_styles[i] == (XIMPreeditNothing | XIMStatusNothing)) { xim_style = xim_styles->supported_styles[i]; break; } } XFree (xim_styles); } XFree( imvalret ); } /* char* windowid = getenv("GODOT_WINDOWID"); if (windowid) { //freopen("/home/punto/stdout", "w", stdout); //reopen("/home/punto/stderr", "w", stderr); x11_window = atol(windowid); XWindowAttributes xwa; XGetWindowAttributes(x11_display,x11_window,&xwa); current_videomode.width = xwa.width; current_videomode.height = xwa.height; }; */ // maybe contextgl wants to be in charge of creating the window //print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height)); #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) ); context_gl->initialize(); rasterizer = memnew( RasterizerGLES2 ); #endif visual_server = memnew( VisualServerRaster(rasterizer) ); if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) { visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD)); } #if 1 // NEW_WM_API // borderless fullscreen window mode if (current_videomode.fullscreen) { // needed for lxde/openbox, possibly others Hints hints; Atom property; hints.flags = 2; hints.decorations = 0; property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); XMapRaised(x11_display, x11_window); XWindowAttributes xwa; XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); XMoveResizeWindow(x11_display, x11_window, 0, 0, xwa.width, xwa.height); // code for netwm-compliants XEvent xev; Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); Atom fullscreen = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", False); memset(&xev, 0, sizeof(xev)); xev.type = ClientMessage; xev.xclient.window = x11_window; xev.xclient.message_type = wm_state; xev.xclient.format = 32; xev.xclient.data.l[0] = 1; xev.xclient.data.l[1] = fullscreen; xev.xclient.data.l[2] = 0; XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); } // disable resizable window if (!current_videomode.resizable) { XSizeHints *xsh; xsh = XAllocSizeHints(); xsh->flags = PMinSize | PMaxSize; XWindowAttributes xwa; if (current_videomode.fullscreen) { XGetWindowAttributes(x11_display,DefaultRootWindow(x11_display),&xwa); } else { XGetWindowAttributes(x11_display,x11_window,&xwa); } xsh->min_width = xwa.width; xsh->max_width = xwa.width; xsh->min_height = xwa.height; xsh->max_height = xwa.height; XSetWMNormalHints(x11_display, x11_window, xsh); XFree(xsh); } #else capture_idle = 0; minimized = false; maximized = false; if (current_videomode.fullscreen) { //set_wm_border(false); set_wm_fullscreen(true); } if (!current_videomode.resizable) { int screen = get_current_screen(); Size2i screen_size = get_screen_size(screen); set_window_size(screen_size); set_window_resizable(false); } #endif AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); audio_driver_index=p_audio_driver; if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) { bool success=false; audio_driver_index=-1; for(int i=0;i<AudioDriverManagerSW::get_driver_count();i++) { if (i==p_audio_driver) continue; AudioDriverManagerSW::get_driver(i)->set_singleton(); if (AudioDriverManagerSW::get_driver(i)->init()==OK) { success=true; print_line("Audio Driver Failed: "+String(AudioDriverManagerSW::get_driver(p_audio_driver)->get_name())); print_line("Using alternate audio driver: "+String(AudioDriverManagerSW::get_driver(i)->get_name())); audio_driver_index=i; break; } } if (!success) { ERR_PRINT("Initializing audio failed."); } } sample_manager = memnew( SampleManagerMallocSW ); audio_server = memnew( AudioServerSW(sample_manager) ); audio_server->init(); spatial_sound_server = memnew( SpatialSoundServerSW ); spatial_sound_server->init(); spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); spatial_sound_2d_server->init(); ERR_FAIL_COND(!visual_server); ERR_FAIL_COND(x11_window==0); XSetWindowAttributes new_attr; new_attr.event_mask=KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask | ButtonMotionMask | KeymapStateMask | ExposureMask | VisibilityChangeMask | StructureNotifyMask | SubstructureNotifyMask | SubstructureRedirectMask | FocusChangeMask | PropertyChangeMask | ColormapChangeMask | OwnerGrabButtonMask; XChangeWindowAttributes(x11_display, x11_window,CWEventMask,&new_attr); XClassHint* classHint; /* set the titlebar name */ XStoreName(x11_display, x11_window, "Godot"); /* set the name and class hints for the window manager to use */ classHint = XAllocClassHint(); if (classHint) { classHint->res_name = (char *)"Godot"; classHint->res_class = (char *)"Godot"; } XSetClassHint(x11_display, x11_window, classHint); XFree(classHint); wm_delete = XInternAtom(x11_display, "WM_DELETE_WINDOW", true); XSetWMProtocols(x11_display, x11_window, &wm_delete, 1); if (xim && xim_style) { xic = XCreateIC (xim,XNInputStyle, xim_style,XNClientWindow,x11_window,XNFocusWindow, x11_window, (char*)NULL); } else { xic=NULL; WARN_PRINT("XCreateIC couldn't create xic"); } XcursorSetTheme(x11_display,"default"); cursor_size = XcursorGetDefaultSize(x11_display); cursor_theme = XcursorGetTheme(x11_display); if (!cursor_theme) { print_line("not found theme"); cursor_theme="default"; } for(int i=0;i<CURSOR_MAX;i++) { cursors[i]=None; img[i]=NULL; } current_cursor=CURSOR_ARROW; if (cursor_theme) { //print_line("cursor theme: "+String(cursor_theme)); for(int i=0;i<CURSOR_MAX;i++) { static const char *cursor_file[]={ "left_ptr", "xterm", "hand2", "cross", "watch", "left_ptr_watch", "fleur", "hand1", "X_cursor", "sb_v_double_arrow", "sb_h_double_arrow", "size_bdiag", "size_fdiag", "hand1", "sb_v_double_arrow", "sb_h_double_arrow", "question_arrow" }; img[i] = XcursorLibraryLoadImage(cursor_file[i],cursor_theme,cursor_size); if (img[i]) { cursors[i]=XcursorImageLoadCursor(x11_display,img[i]); //print_line("found cursor: "+String(cursor_file[i])+" id "+itos(cursors[i])); } else { if (OS::is_stdout_verbose()) print_line("failed cursor: "+String(cursor_file[i])); } } } { Pixmap cursormask; XGCValues xgc; GC gc; XColor col; Cursor cursor; cursormask = XCreatePixmap(x11_display, RootWindow(x11_display,DefaultScreen(x11_display)), 1, 1, 1); xgc.function = GXclear; gc = XCreateGC(x11_display, cursormask, GCFunction, &xgc); XFillRectangle(x11_display, cursormask, gc, 0, 0, 1, 1); col.pixel = 0; col.red = 0; col.flags = 4; cursor = XCreatePixmapCursor(x11_display, cursormask, cursormask, &col, &col, 0, 0); XFreePixmap(x11_display, cursormask); XFreeGC(x11_display, gc); if (cursor == None) { ERR_PRINT("FAILED CREATING CURSOR"); } null_cursor=cursor; } set_cursor_shape(CURSOR_BUSY); visual_server->init(); // physics_server = memnew( PhysicsServerSW ); physics_server->init(); //physics_2d_server = memnew( Physics2DServerSW ); physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>(); physics_2d_server->init(); input = memnew( InputDefault ); #ifdef JOYDEV_ENABLED joystick = memnew( joystick_linux(input)); #endif _ensure_data_dir(); }