From d269344bbd19d9653fff3c2a230261b8fa00d7f6 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Thu, 15 Jan 2015 22:50:23 +0900 Subject: [PATCH] WIP -- set_resizable() + is_resizable added --- core/bind/core_bind.cpp | 11 +++- core/bind/core_bind.h | 2 + core/os/os.h | 2 + demos/misc/window_management/control.gd | 28 ++++++++- .../window_management/window_management.scn | Bin 3787 -> 3897 bytes platform/x11/os_x11.cpp | 57 +++++++++++++----- platform/x11/os_x11.h | 9 ++- 7 files changed, 91 insertions(+), 18 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 48cd43ccdc..1fb6f96e71 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -220,6 +220,14 @@ void _OS::set_fullscreen(bool p_enabled) { bool _OS::is_fullscreen() const { return OS::get_singleton()->is_fullscreen(); } + +void _OS::set_resizable(bool p_enabled) { + OS::get_singleton()->set_resizable(p_enabled); +} + +bool _OS::is_resizable() const { + return OS::get_singleton()->is_resizable(); +} #endif void _OS::set_use_file_access_save_and_swap(bool p_enable) { @@ -232,7 +240,6 @@ bool _OS::is_video_mode_resizable(int p_screen) const { OS::VideoMode vm; vm = OS::get_singleton()->get_video_mode(p_screen); return vm.resizable; - } Array _OS::get_fullscreen_mode_list(int p_screen) const { @@ -690,6 +697,8 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_window_size"),&_OS::set_window_size); ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled"),&_OS::set_fullscreen); ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); + ObjectTypeDB::bind_method(_MD("set_resizable","enabled"),&_OS::set_resizable); + ObjectTypeDB::bind_method(_MD("is_resizable"),&_OS::is_resizable); #endif ObjectTypeDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 99ecb765c7..7ffd7e9e7c 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -120,6 +120,8 @@ public: virtual void set_window_size(const Size2& p_size); void set_fullscreen(bool p_enabled); bool is_fullscreen() const; + void set_resizable(bool p_enabled); + bool is_resizable() const; #endif Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); diff --git a/core/os/os.h b/core/os/os.h index 2d4e937974..f1a9de1edf 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -162,6 +162,8 @@ public: virtual void set_window_size(const Size2 p_size)=0; virtual void set_fullscreen(bool p_enabled)=0; virtual bool is_fullscreen() const=0; + virtual void set_resizable(bool p_enabled)=0; + virtual bool is_resizable() const=0; #endif virtual void set_iterations_per_second(int p_ips); diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index ce17db6b00..c867bd21db 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -2,10 +2,18 @@ extends Control func _fixed_process(delta): + + var modetext = "Mode:\n" + if(OS.is_fullscreen()): - get_node("Label_Fullscreen").set_text("Mode:\nFullscreen") + modetext += "Fullscreen\n" else: - get_node("Label_Fullscreen").set_text("Mode:\nWindowed") + modetext += "Windowed\n" + + if(!OS.is_resizable()): + modetext += "FixedSize\n" + + get_node("Label_Mode").set_text(modetext) get_node("Label_Position").set_text( str("Position:\n", OS.get_window_position() ) ) @@ -19,6 +27,7 @@ func _fixed_process(delta): get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position())) + if(OS.get_screen_count() > 1): get_node("Button_Screen1").show() get_node("Label_Screen1_Resolution").show() @@ -42,6 +51,9 @@ func _fixed_process(delta): if( Input.is_action_pressed("ui_down")): OS.set_fullscreen(false) + get_node("Button_FixedSize").set_pressed( !OS.is_resizable() ) + + func _ready(): set_fixed_process(true) @@ -67,3 +79,15 @@ func _on_Button_Screen0_pressed(): func _on_Button_Screen1_pressed(): OS.set_screen(1) + + + + + +func _on_Button_FixedSize_pressed(): + if(OS.is_resizable()): + OS.set_resizable(false) + else: + OS.set_resizable(true) + + diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 9d55174dcec9ff01ca27f20c4461a89722a12c69..befc177b5e09d4c07cc3657e1cc5da662998c3d3 100644 GIT binary patch delta 2588 zcmX>tyHidwDA?JV0R#jX7*f?37;dvOFqE+}Fr1huxstJHjO+NL2Nu0g7q$sr{IU`>2E@NhXqDkwmqYqsJ z7@bNL?OF5U-AZ$E6l9oEQ}dE9HHaq3PBvxHuiwW|l2oRk%TVBA!BCR=lOa(hks&W( zYC|q#ysv69LrBB&1%ix0sSaloWfurCxn)+UODc*a)GZKETd1&u!QcU>5QAY7JBv?Z zQfiJutnx0m!UVpAvx}UP44lPM>lpQORi{2+;$=*%NN{P8W-cyCEqK7h$6Sz@o|@p< zAj@1|mY7r8Fr$H=Iklo7-o-az24hjadZuc4f(k=%VyXg{Ba_Qs_QcYX{PLp2f`m%O z(gNj)YEdn&4%{kF7~+#4MIcht!J7hQ>V2Dpzr1pWS zAg5H-jv-$4F;huuv8KrbW)07cieg%_31SZ34)zY;jxTcvc3?Ol-j&&~-=W+=++n+l zhL(n+$SG$B2?rZSBbS6|2R;X8M=OQ`<+sc^@x^({;tusi4h#-b4$KTy8oM*>m~FYz z?HvRhO;k-EaO!%LFy^PV{a|MhdUe>hXWL;10|(}WD2E#74-Ntj+ziGI9WL)3gq-u4 zQc}~DS804>D#|a>%ykH2s=29T=gU1U8c4h_!6DJ2@ha~2* z%+zwP3yo4@4ziA^jNAiuMEvIV<#%%#J!9r4axhju&2DmODEYTaEk z!)fOMSyyxB#N4Dzch%-)*_8?6%(G@n+8tnKU{F~>P_eI;9$ofslf4oA&sRVr!+lNA(JJ!C^a=tA>Bbv zfq`8?fi*a}D6^m>!JL6nfzM%<0|Nt#1B(KKL)YX2j)Ho51qOx#4)qTA9X>n!e#pe< z@QlAGwb)8uKRG|Iq$oc}FFj?UFyjKp2787N3FpD_;poM{t-#3)Dk2)=7icj~b577= zY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^$`+oPmy%zedSD~Nqyz~k0}fE`EXmBzvsz%p z@F+o&fz2UHq5Xg;gJeR2gGWOHL-7F#2FC{s5^T<;MMbH3B?lxJViwF|XjmxCkeQ&t zD9UiakCps9|VoFkx)yNYG&tW?)#5$7rDNfMMAIEjNZ~3$z&KBxpTg z3}-NWz#Y!8YJm>Jh6Ei5pE=wy$>BRgp0W;8F@u6aje{w}{{;*RdkaqmwVD4D%!0));f!!(6L7Ra`!Nq}{fmeau!I*(>0XqZ#0(OUN z2XUue4(tp<3gQmI511Joc^sG>W;@tFV4v;m>QL`+*`eAo)4`cROu@yWpFv!K-J##v z(4pTY(%~?Jl!CZJF@v-MyTg1283lHS(+si-><*h5gcCde7znZ~aA>83I zgNFjU!(|3f1$GC19tJN3cBga(Zv}S8`IB{cWa@<{lNRN!{G1 zc%b*#8O&Y(Ao{TjKS(U_f!<@67(i{%?{>In44X?U7B6rKal?H68w~1|EPLB zLzqIo>tlv+1$I|+hKL3143P`i8KM-}9po9J71*7(GsG-lcbV;$?$YdL%n+*}?y#L9 z4jh2-3)qzW=MKy zCw%1bL1Fjr4~vC8@+Zp5)*clkXa?A=W zpxn%0tia5`ufWV;0@BM6s=)4G&0xBKoxxRs-J#x`!CZlzL0^HH!A*gg!9anT!9szV z!BByj!4hl;_7sxNV7Gvs!Crx#K~#a6!BK(PA)g^kft`U(ftev(f!To{GbkM%gMtzi z{|rV7%nW`C%nTd~%=HYh3e2!DeJC!>kfxvx@&-5%9qk`73p=_$EEaa$4ho#~hjzjY zW(w{PnT4IK9~KKctpm6t(If!RUSxs)MGf!moOQ-Rs}r2~V5rh_;`jsg!uwgU43ap#!_#2IoQ pFo`=KJRr`H_kc;9fm4C|fH*_G0yj4ksHMihzz`H1min_height = xwa.height; xsh->max_height = xwa.height; XSetWMNormalHints(x11_display, x11_window, xsh); + XFree(xsh); } + current_videomode.resizable; AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); @@ -277,19 +279,19 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XChangeWindowAttributes(x11_display, x11_window,CWEventMask,&new_attr); - XClassHint* classHint; + XClassHint* classHint; - /* set the titlebar name */ - XStoreName(x11_display, x11_window, "Godot"); + /* 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 = "Godot"; - classHint->res_class = "Godot"; - } - XSetClassHint(x11_display, x11_window, classHint); - XFree(classHint); + /* set the name and class hints for the window manager to use */ + classHint = XAllocClassHint(); + if (classHint) { + classHint->res_name = "Godot"; + classHint->res_class = "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); @@ -708,6 +710,9 @@ void OS_X11::set_fullscreen(bool p_enabled) { if(p_enabled && current_videomode.fullscreen) return; + if(!current_videomode.resizable) + set_resizable(true); + if(p_enabled) { window_data.size = get_window_size(); window_data.position = get_window_position(); @@ -734,11 +739,37 @@ void OS_X11::set_fullscreen(bool p_enabled) { } visual_server->init(); + } bool OS_X11::is_fullscreen() const { return current_videomode.fullscreen; } + +void OS_X11::set_resizable(bool p_enabled) { + + if(!current_videomode.fullscreen) { + XSizeHints *xsh; + xsh = XAllocSizeHints(); + xsh->flags = p_enabled ? 0L : PMinSize | PMaxSize; + if(!p_enabled) { + XWindowAttributes xwa; + 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; + printf("%d %d\n", xwa.width, xwa.height); + } + XSetWMNormalHints(x11_display, x11_window, xsh); + XFree(xsh); + current_videomode.resizable = p_enabled; + } +} + +bool OS_X11::is_resizable() const { + return current_videomode.resizable; +} #endif InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) { @@ -1688,6 +1719,4 @@ OS_X11::OS_X11() { minimized = false; xim_style=NULL; mouse_mode=MOUSE_MODE_VISIBLE; - - }; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 72d212c131..d286efe7b8 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -160,10 +160,15 @@ class OS_X11 : public OS_Unix { Joystick joysticks[JOYSTICKS_MAX]; #ifdef EXPERIMENTAL_WM_API + // This struct saves the values of the window before going fullscreen + // to be able to restore the same state after leaving fullscreen struct { + bool resizable; Point2i position; Size2i size; - } window_data; + } window_data; + + bool maximized; void set_wm_border(bool p_enabled); void set_wm_fullscreen(bool p_enabled); #endif @@ -234,6 +239,8 @@ public: virtual void set_window_size(const Size2 p_size); virtual void set_fullscreen(bool p_enabled); virtual bool is_fullscreen() const; + virtual void set_resizable(bool p_enabled); + virtual bool is_resizable() const; #endif virtual void move_window_to_foreground();