summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/windows/os_windows.cpp188
-rw-r--r--platform/windows/os_windows.h36
-rw-r--r--platform/x11/os_x11.cpp31
-rw-r--r--platform/x11/os_x11.h28
4 files changed, 253 insertions, 30 deletions
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 50c42448f4..a8768ea9fd 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -171,6 +171,8 @@ void OS_Windows::initialize_core() {
last_button_state=0;
//RedirectIOToConsole();
+ maximized=false;
+ minimized=false;
ThreadWindows::make_default();
SemaphoreWindows::make_default();
@@ -1007,6 +1009,23 @@ void OS_Windows::process_joysticks() {
};
};
+
+BOOL CALLBACK OS_Windows::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
+ OS_Windows *self=(OS_Windows*)OS::get_singleton();
+ MonitorInfo minfo;
+ minfo.hMonitor=hMonitor;
+ minfo.hdcMonitor=hdcMonitor;
+ minfo.rect.pos.x=lprcMonitor->left;
+ minfo.rect.pos.y=lprcMonitor->top;
+ minfo.rect.size.x=lprcMonitor->right - lprcMonitor->left;
+ minfo.rect.size.y=lprcMonitor->bottom - lprcMonitor->top;
+
+ self->monitor_info.push_back(minfo);
+
+ return TRUE;
+}
+
+
void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) {
@@ -1045,6 +1064,9 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_
}
+ EnumDisplayMonitors(NULL,NULL,MonitorEnumProc,0);
+
+ print_line("DETECTED MONITORS: "+itos(monitor_info.size()));
if (video_mode.fullscreen) {
DEVMODE current;
@@ -1475,6 +1497,172 @@ void OS_Windows::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen)
}
+int OS_Windows::get_screen_count() const {
+
+ return monitor_info.size();
+}
+int OS_Windows::get_current_screen() const{
+
+ HMONITOR monitor = MonitorFromWindow(hWnd,MONITOR_DEFAULTTONEAREST);
+ for(int i=0;i<monitor_info.size();i++) {
+ if (monitor_info[i].hMonitor==monitor)
+ return i;
+ }
+
+ return 0;
+}
+void OS_Windows::set_current_screen(int p_screen){
+
+ ERR_FAIL_INDEX(p_screen,monitor_info.size());
+
+ Vector2 ofs = get_window_position() - get_screen_position(get_current_screen());
+ set_window_position(ofs+get_screen_position(p_screen));
+
+}
+
+Point2 OS_Windows::get_screen_position(int p_screen) const{
+
+ ERR_FAIL_INDEX_V(p_screen,monitor_info.size(),Point2());
+ return Vector2( monitor_info[p_screen].rect.pos );
+
+}
+Size2 OS_Windows::get_screen_size(int p_screen) const{
+
+ ERR_FAIL_INDEX_V(p_screen,monitor_info.size(),Point2());
+ return Vector2( monitor_info[p_screen].rect.size );
+
+}
+Point2 OS_Windows::get_window_position() const{
+
+ RECT r;
+ GetWindowRect(hWnd,&r);
+ return Point2(r.left,r.top);
+}
+void OS_Windows::set_window_position(const Point2& p_position){
+
+ RECT r;
+ GetWindowRect(hWnd,&r);
+ MoveWindow(hWnd,p_position.x,p_position.y,r.right-r.left,r.bottom-r.top,TRUE);
+
+}
+Size2 OS_Windows::get_window_size() const{
+
+ RECT r;
+ GetWindowRect(hWnd,&r);
+ return Vector2(r.right-r.left,r.bottom-r.top);
+
+}
+void OS_Windows::set_window_size(const Size2 p_size){
+
+ RECT r;
+ GetWindowRect(hWnd,&r);
+ MoveWindow(hWnd,r.left,r.top,p_size.x,p_size.y,TRUE);
+
+}
+void OS_Windows::set_window_fullscreen(bool p_enabled){
+
+ if (video_mode.fullscreen==p_enabled)
+ return;
+
+ if (p_enabled) {
+
+ GetWindowRect(hWnd,&pre_fs_rect);
+
+ int cs = get_current_screen();
+ Point2 pos = get_screen_position(cs);
+ Size2 size = get_screen_size(cs);
+ RECT WindowRect;
+ WindowRect.left = pos.x;
+ WindowRect.top = pos.y;
+ WindowRect.bottom = pos.y+size.y;
+ WindowRect.right = pos.x+size.x;
+
+ DWORD dwExStyle=WS_EX_APPWINDOW;
+ DWORD dwStyle=WS_POPUP;
+
+ AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
+
+ video_mode.fullscreen=true;
+ video_mode.width=size.x;
+ video_mode.height=size.y;
+
+
+ } else {
+
+ DWORD dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
+ DWORD dwStyle=WS_OVERLAPPEDWINDOW;
+ if (!video_mode.resizable) {
+ dwStyle &= ~WS_THICKFRAME;
+ dwStyle &= ~WS_MAXIMIZEBOX;
+ }
+ AdjustWindowRectEx(&pre_fs_rect, dwStyle, FALSE, dwExStyle);
+ video_mode.fullscreen=false;
+ video_mode.width=pre_fs_rect.right-pre_fs_rect.left;
+ video_mode.height=pre_fs_rect.bottom-pre_fs_rect.top;
+
+ }
+
+
+}
+bool OS_Windows::is_window_fullscreen() const{
+
+ return video_mode.fullscreen;
+}
+void OS_Windows::set_window_resizable(bool p_enabled){
+
+ if (video_mode.fullscreen || video_mode.resizable==p_enabled)
+ return;
+
+ GetWindowRect(hWnd,&pre_fs_rect);
+ DWORD dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
+ DWORD dwStyle=WS_OVERLAPPEDWINDOW;
+ if (!p_enabled) {
+ dwStyle &= ~WS_THICKFRAME;
+ dwStyle &= ~WS_MAXIMIZEBOX;
+ }
+ AdjustWindowRectEx(&pre_fs_rect, dwStyle, FALSE, dwExStyle);
+ video_mode.resizable=p_enabled;
+
+}
+bool OS_Windows::is_window_resizable() const{
+
+ return video_mode.resizable;
+}
+void OS_Windows::set_window_minimized(bool p_enabled){
+
+ if (p_enabled) {
+ maximized=false;
+ minimized=true;
+ ShowWindow(hWnd,SW_MINIMIZE);
+ } else {
+ ShowWindow(hWnd,SW_RESTORE);
+ maximized=false;
+ minimized=false;
+ }
+}
+bool OS_Windows::is_window_minimized() const{
+
+ return minimized;
+
+}
+void OS_Windows::set_window_maximized(bool p_enabled){
+
+ if (p_enabled) {
+ maximized=true;
+ minimized=false;
+ ShowWindow(hWnd,SW_MAXIMIZE);
+ } else {
+ ShowWindow(hWnd,SW_RESTORE);
+ maximized=false;
+ minimized=false;
+ }
+}
+bool OS_Windows::is_window_maximized() const{
+
+ return maximized;
+}
+
+
void OS_Windows::print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type) {
HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index 210e25d2d6..c39b3c74a4 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -86,7 +86,7 @@ class OS_Windows : public OS {
uint64_t ticks_start;
uint64_t ticks_per_second;
- bool minimized;
+
bool old_invalid;
bool outside;
int old_x,old_y;
@@ -196,6 +196,22 @@ protected:
};
Map<ProcessID, ProcessInfo>* process_map;
+ struct MonitorInfo {
+ HMONITOR hMonitor;
+ HDC hdcMonitor;
+ Rect2 rect;
+
+
+ };
+
+ RECT pre_fs_rect;
+ Vector<MonitorInfo> monitor_info;
+ bool maximized;
+ bool minimized;
+
+ static BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData);
+
+
public:
LRESULT WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam);
@@ -218,6 +234,24 @@ public:
virtual VideoMode get_video_mode(int p_screen=0) const;
virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const;
+ virtual int get_screen_count() const;
+ virtual int get_current_screen() const;
+ virtual void set_current_screen(int p_screen);
+ virtual Point2 get_screen_position(int p_screen=0) const;
+ virtual Size2 get_screen_size(int p_screen=0) const;
+ virtual Point2 get_window_position() const;
+ virtual void set_window_position(const Point2& p_position);
+ virtual Size2 get_window_size() const;
+ virtual void set_window_size(const Size2 p_size);
+ virtual void set_window_fullscreen(bool p_enabled);
+ virtual bool is_window_fullscreen() const;
+ virtual void set_window_resizable(bool p_enabled);
+ virtual bool is_window_resizable() const;
+ virtual void set_window_minimized(bool p_enabled);
+ virtual bool is_window_minimized() const;
+ virtual void set_window_maximized(bool p_enabled);
+ virtual bool is_window_maximized() const;
+
virtual MainLoop *get_main_loop() const;
virtual String get_name();
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index e974fe5f9f..5b36df6a53 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -36,7 +36,7 @@
#include "servers/physics/physics_server_sw.h"
#include "X11/Xutil.h"
-#ifdef NEW_WM_API
+
#include "X11/Xatom.h"
#include "X11/extensions/Xinerama.h"
// ICCCM
@@ -46,7 +46,7 @@
#define _NET_WM_STATE_REMOVE 0L // remove/unset property
#define _NET_WM_STATE_ADD 1L // add/set property
#define _NET_WM_STATE_TOGGLE 2L // toggle property
-#endif
+
#include "main/main.h"
@@ -187,7 +187,8 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD));
}
-#ifndef NEW_WM_API
+#if 1
+ // NEW_WM_API
// borderless fullscreen window mode
if (current_videomode.fullscreen) {
// needed for lxde/openbox, possibly others
@@ -551,7 +552,7 @@ void OS_X11::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) cons
}
-#ifdef NEW_WM_API
+//#ifdef NEW_WM_API
#if 0
// Just now not needed. Can be used for a possible OS.set_border(bool) method
void OS_X11::set_wm_border(bool p_enabled) {
@@ -597,7 +598,7 @@ int OS_X11::get_screen_count() const {
return count;
}
-int OS_X11::get_screen() const {
+int OS_X11::get_current_screen() const {
int x,y;
Window child;
XTranslateCoordinates( x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child);
@@ -612,7 +613,7 @@ int OS_X11::get_screen() const {
return 0;
}
-void OS_X11::set_screen(int p_screen) {
+void OS_X11::set_current_screen(int p_screen) {
int count = get_screen_count();
if(p_screen >= count) return;
@@ -729,18 +730,18 @@ void OS_X11::set_window_size(const Size2 p_size) {
XResizeWindow(x11_display, x11_window, p_size.x, p_size.y);
}
-void OS_X11::set_fullscreen(bool p_enabled) {
+void OS_X11::set_window_fullscreen(bool p_enabled) {
set_wm_fullscreen(p_enabled);
current_videomode.fullscreen = p_enabled;
visual_server->init();
}
-bool OS_X11::is_fullscreen() const {
+bool OS_X11::is_window_fullscreen() const {
return current_videomode.fullscreen;
}
-void OS_X11::set_resizable(bool p_enabled) {
+void OS_X11::set_window_resizable(bool p_enabled) {
XSizeHints *xsh;
xsh = XAllocSizeHints();
xsh->flags = p_enabled ? 0L : PMinSize | PMaxSize;
@@ -757,11 +758,11 @@ void OS_X11::set_resizable(bool p_enabled) {
current_videomode.resizable = p_enabled;
}
-bool OS_X11::is_resizable() const {
+bool OS_X11::is_window_resizable() const {
return current_videomode.resizable;
}
-void OS_X11::set_minimized(bool p_enabled) {
+void OS_X11::set_window_minimized(bool p_enabled) {
// Using ICCCM -- Inter-Client Communication Conventions Manual
XEvent xev;
Atom wm_change = XInternAtom(x11_display, "WM_CHANGE_STATE", False);
@@ -790,7 +791,7 @@ void OS_X11::set_minimized(bool p_enabled) {
XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
}
-bool OS_X11::is_minimized() const {
+bool OS_X11::is_window_minimized() const {
// Using ICCCM -- Inter-Client Communication Conventions Manual
Atom property = XInternAtom(x11_display,"WM_STATE", True);
Atom type;
@@ -822,7 +823,7 @@ bool OS_X11::is_minimized() const {
return false;
}
-void OS_X11::set_maximized(bool p_enabled) {
+void OS_X11::set_window_maximized(bool p_enabled) {
// Using EWMH -- Extended Window Manager Hints
XEvent xev;
Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False);
@@ -843,7 +844,7 @@ void OS_X11::set_maximized(bool p_enabled) {
maximized = p_enabled;
}
-bool OS_X11::is_maximized() const {
+bool OS_X11::is_window_maximized() const {
// Using EWMH -- Extended Window Manager Hints
Atom property = XInternAtom(x11_display,"_NET_WM_STATE",False );
Atom type;
@@ -888,7 +889,7 @@ bool OS_X11::is_maximized() const {
return false;
}
-#endif
+
InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) {
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index ffa1ce00b3..ebcb0dc2fc 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -159,12 +159,12 @@ class OS_X11 : public OS_Unix {
int joystick_count;
Joystick joysticks[JOYSTICKS_MAX];
-#ifdef NEW_WM_API
+
unsigned int capture_idle;
bool maximized;
//void set_wm_border(bool p_enabled);
void set_wm_fullscreen(bool p_enabled);
-#endif
+
protected:
@@ -220,25 +220,25 @@ public:
virtual VideoMode get_video_mode(int p_screen=0) const;
virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const;
-#ifdef NEW_WM_API
+
virtual int get_screen_count() const;
- virtual int get_screen() const;
- virtual void set_screen(int p_screen);
+ virtual int get_current_screen() const;
+ virtual void set_current_screen(int p_screen);
virtual Point2 get_screen_position(int p_screen=0) const;
virtual Size2 get_screen_size(int p_screen=0) const;
virtual Point2 get_window_position() const;
virtual void set_window_position(const Point2& p_position);
virtual Size2 get_window_size() const;
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;
- virtual void set_minimized(bool p_enabled);
- virtual bool is_minimized() const;
- virtual void set_maximized(bool p_enabled);
- virtual bool is_maximized() const;
-#endif
+ virtual void set_window_fullscreen(bool p_enabled);
+ virtual bool is_window_fullscreen() const;
+ virtual void set_window_resizable(bool p_enabled);
+ virtual bool is_window_resizable() const;
+ virtual void set_window_minimized(bool p_enabled);
+ virtual bool is_window_minimized() const;
+ virtual void set_window_maximized(bool p_enabled);
+ virtual bool is_window_maximized() const;
+
virtual void move_window_to_foreground();
void run();