summaryrefslogtreecommitdiff
path: root/platform/x11/os_x11.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/x11/os_x11.cpp')
-rw-r--r--platform/x11/os_x11.cpp203
1 files changed, 168 insertions, 35 deletions
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index c2e7b561d3..6421dc270f 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -534,22 +534,26 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
}
{
- Pixmap cursormask;
- XGCValues xgc;
- GC gc;
- XColor col;
- Cursor cursor;
+ // Creating an empty/transparent cursor
+
+ // Create 1x1 bitmap
+ Pixmap cursormask = XCreatePixmap(x11_display,
+ RootWindow(x11_display, DefaultScreen(x11_display)), 1, 1, 1);
- cursormask = XCreatePixmap(x11_display, RootWindow(x11_display, DefaultScreen(x11_display)), 1, 1, 1);
+ // Fill with zero
+ XGCValues xgc;
xgc.function = GXclear;
- gc = XCreateGC(x11_display, cursormask, GCFunction, &xgc);
+ GC 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,
+
+ // Color value doesn't matter. Mask zero means no foreground or background will be drawn
+ XColor col = {};
+
+ Cursor cursor = XCreatePixmapCursor(x11_display,
+ cursormask, // source (using cursor mask as placeholder, since it'll all be ignored)
+ cursormask, // mask
&col, &col, 0, 0);
+
XFreePixmap(x11_display, cursormask);
XFreeGC(x11_display, gc);
@@ -579,6 +583,9 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
AudioDriverManager::initialize(p_audio_driver);
+ ///@TODO implement a subclass for Linux and instantiate that instead
+ camera_server = memnew(CameraServer);
+
input = memnew(InputDefault);
window_has_focus = true; // Set focus to true at init
@@ -589,7 +596,7 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
power_manager = memnew(PowerX11);
- if (p_desired.layered_splash) {
+ if (p_desired.layered) {
set_window_per_pixel_transparency_enabled(true);
}
@@ -779,6 +786,8 @@ void OS_X11::finalize() {
memdelete(input);
+ memdelete(camera_server);
+
visual_server->finish();
memdelete(visual_server);
//memdelete(rasterizer);
@@ -997,28 +1006,40 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) {
XFlush(x11_display);
- if (!p_enabled && !is_window_resizable()) {
+ if (!p_enabled) {
// Reset the non-resizable flags if we un-set these before.
Size2 size = get_window_size();
XSizeHints *xsh;
-
xsh = XAllocSizeHints();
- xsh->flags = PMinSize | PMaxSize;
- xsh->min_width = size.x;
- xsh->max_width = size.x;
- xsh->min_height = size.y;
- xsh->max_height = size.y;
-
+ if (!is_window_resizable()) {
+ xsh->flags = PMinSize | PMaxSize;
+ xsh->min_width = size.x;
+ xsh->max_width = size.x;
+ xsh->min_height = size.y;
+ xsh->max_height = size.y;
+ } else {
+ xsh->flags = 0L;
+ if (min_size != Size2()) {
+ xsh->flags |= PMinSize;
+ xsh->min_width = min_size.x;
+ xsh->min_height = min_size.y;
+ }
+ if (max_size != Size2()) {
+ xsh->flags |= PMaxSize;
+ xsh->max_width = max_size.x;
+ xsh->max_height = max_size.y;
+ }
+ }
XSetWMNormalHints(x11_display, x11_window, xsh);
XFree(xsh);
}
- if (!p_enabled && !get_borderless_window()) {
- // put decorations back if the window wasn't suppoesed to be borderless
+ if (!p_enabled) {
+ // put back or remove decorations according to the last set borderless state
Hints hints;
Atom property;
hints.flags = 2;
- hints.decorations = 1;
+ hints.decorations = current_videomode.borderless_window ? 0 : 1;
property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True);
XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);
}
@@ -1235,6 +1256,72 @@ Size2 OS_X11::get_real_window_size() const {
return Size2(w, h);
}
+Size2 OS_X11::get_max_window_size() const {
+ return max_size;
+}
+
+Size2 OS_X11::get_min_window_size() const {
+ return min_size;
+}
+
+void OS_X11::set_min_window_size(const Size2 p_size) {
+
+ if ((p_size != Size2()) && (max_size != Size2()) && ((p_size.x > max_size.x) || (p_size.y > max_size.y))) {
+ WARN_PRINT("Minimum window size can't be larger than maximum window size!");
+ return;
+ }
+ min_size = p_size;
+
+ if (is_window_resizable()) {
+ XSizeHints *xsh;
+ xsh = XAllocSizeHints();
+ xsh->flags = 0L;
+ if (min_size != Size2()) {
+ xsh->flags |= PMinSize;
+ xsh->min_width = min_size.x;
+ xsh->min_height = min_size.y;
+ }
+ if (max_size != Size2()) {
+ xsh->flags |= PMaxSize;
+ xsh->max_width = max_size.x;
+ xsh->max_height = max_size.y;
+ }
+ XSetWMNormalHints(x11_display, x11_window, xsh);
+ XFree(xsh);
+
+ XFlush(x11_display);
+ }
+}
+
+void OS_X11::set_max_window_size(const Size2 p_size) {
+
+ if ((p_size != Size2()) && ((p_size.x < min_size.x) || (p_size.y < min_size.y))) {
+ WARN_PRINT("Maximum window size can't be smaller than minimum window size!");
+ return;
+ }
+ max_size = p_size;
+
+ if (is_window_resizable()) {
+ XSizeHints *xsh;
+ xsh = XAllocSizeHints();
+ xsh->flags = 0L;
+ if (min_size != Size2()) {
+ xsh->flags |= PMinSize;
+ xsh->min_width = min_size.x;
+ xsh->min_height = min_size.y;
+ }
+ if (max_size != Size2()) {
+ xsh->flags |= PMaxSize;
+ xsh->max_width = max_size.x;
+ xsh->max_height = max_size.y;
+ }
+ XSetWMNormalHints(x11_display, x11_window, xsh);
+ XFree(xsh);
+
+ XFlush(x11_display);
+ }
+}
+
void OS_X11::set_window_size(const Size2 p_size) {
if (current_videomode.width == p_size.width && current_videomode.height == p_size.height)
@@ -1247,17 +1334,29 @@ void OS_X11::set_window_size(const Size2 p_size) {
int old_h = xwa.height;
// If window resizable is disabled we need to update the attributes first
+ XSizeHints *xsh;
+ xsh = XAllocSizeHints();
if (!is_window_resizable()) {
- XSizeHints *xsh;
- xsh = XAllocSizeHints();
xsh->flags = PMinSize | PMaxSize;
xsh->min_width = p_size.x;
xsh->max_width = p_size.x;
xsh->min_height = p_size.y;
xsh->max_height = p_size.y;
- XSetWMNormalHints(x11_display, x11_window, xsh);
- XFree(xsh);
+ } else {
+ xsh->flags = 0L;
+ if (min_size != Size2()) {
+ xsh->flags |= PMinSize;
+ xsh->min_width = min_size.x;
+ xsh->min_height = min_size.y;
+ }
+ if (max_size != Size2()) {
+ xsh->flags |= PMaxSize;
+ xsh->max_width = max_size.x;
+ xsh->max_height = max_size.y;
+ }
}
+ XSetWMNormalHints(x11_display, x11_window, xsh);
+ XFree(xsh);
// Resize the window
XResizeWindow(x11_display, x11_window, p_size.x, p_size.y);
@@ -1303,20 +1402,37 @@ bool OS_X11::is_window_fullscreen() const {
}
void OS_X11::set_window_resizable(bool p_enabled) {
- XSizeHints *xsh;
- Size2 size = get_window_size();
+ XSizeHints *xsh;
xsh = XAllocSizeHints();
- xsh->flags = p_enabled ? 0L : PMinSize | PMaxSize;
if (!p_enabled) {
+ Size2 size = get_window_size();
+
+ xsh->flags = PMinSize | PMaxSize;
xsh->min_width = size.x;
xsh->max_width = size.x;
xsh->min_height = size.y;
xsh->max_height = size.y;
+ } else {
+ xsh->flags = 0L;
+ if (min_size != Size2()) {
+ xsh->flags |= PMinSize;
+ xsh->min_width = min_size.x;
+ xsh->min_height = min_size.y;
+ }
+ if (max_size != Size2()) {
+ xsh->flags |= PMaxSize;
+ xsh->max_width = max_size.x;
+ xsh->max_height = max_size.y;
+ }
}
+
XSetWMNormalHints(x11_display, x11_window, xsh);
XFree(xsh);
+
current_videomode.resizable = p_enabled;
+
+ XFlush(x11_display);
}
bool OS_X11::is_window_resizable() const {
@@ -1527,7 +1643,7 @@ bool OS_X11::is_window_always_on_top() const {
void OS_X11::set_borderless_window(bool p_borderless) {
- if (current_videomode.borderless_window == p_borderless)
+ if (get_borderless_window() == p_borderless)
return;
if (!p_borderless && layered_window)
@@ -1547,7 +1663,24 @@ void OS_X11::set_borderless_window(bool p_borderless) {
}
bool OS_X11::get_borderless_window() {
- return current_videomode.borderless_window;
+
+ bool borderless = current_videomode.borderless_window;
+ Atom prop = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True);
+ if (prop != None) {
+
+ Atom type;
+ int format;
+ unsigned long len;
+ unsigned long remaining;
+ unsigned char *data = NULL;
+ if (XGetWindowProperty(x11_display, x11_window, prop, 0, sizeof(Hints), False, AnyPropertyType, &type, &format, &len, &remaining, &data) == Success) {
+ if (data && (format == 32) && (len >= 5)) {
+ borderless = !((Hints *)data)->decorations;
+ }
+ XFree(data);
+ }
+ }
+ return borderless;
}
void OS_X11::request_attention() {
@@ -2374,7 +2507,7 @@ void OS_X11::process_xevents() {
Vector<String> files = String((char *)p.data).split("\n", false);
for (int i = 0; i < files.size(); i++) {
- files.write[i] = files[i].replace("file://", "").http_unescape().strip_escapes();
+ files.write[i] = files[i].replace("file://", "").http_unescape().strip_edges();
}
main_loop->drop_files(files);
@@ -2592,7 +2725,7 @@ String OS_X11::get_clipboard() const {
return ret;
}
-String OS_X11::get_name() {
+String OS_X11::get_name() const {
return "X11";
}