[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: "Coordination of admins/developers of the game programming library Allegro" <alleg-developers@xxxxxxxxxx>
- Subject: [AD] ALLEGRO_MAXIMIZED
- From: Elias Pschernig <elias@xxxxxxxxxx>
- Date: Thu, 9 Jul 2015 12:07:17 -0400
Hi, this is a small patch to add an ALLEGRO_MAXIMIZED display flag, with an X11 implementation. I needed it for my game so once I boot to Windows the next time (might not be this year) I can try and also implement it for Windows.
I'll commit it if nobody sees a problem.
PS. Is sending a patch here still the preferred way or do we think github pull requests are easier to view these days?
From dead651904e318238298e6fb07419d28c457062b Mon Sep 17 00:00:00 2001
From: Elias Pschernig <elias@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 9 Jul 2015 11:54:02 -0400
Subject: [PATCH] Added an ALLEGRO_MAXIMIZED display flag.
Only implemented for X11.
---
docs/src/refman/display.txt | 6 +++
examples/ex_resize2.c | 24 +++++++++++
include/allegro5/display.h | 3 +-
include/allegro5/internal/aintern_xwindow.h | 2 +
src/x/xdisplay.c | 11 +++++
src/x/xwindow.c | 64 +++++++++++++++++++++++++++++
6 files changed, 109 insertions(+), 1 deletion(-)
diff --git a/docs/src/refman/display.txt b/docs/src/refman/display.txt
index f659e28..7527206 100644
--- a/docs/src/refman/display.txt
+++ b/docs/src/refman/display.txt
@@ -126,6 +126,11 @@ ALLEGRO_RESIZABLE
: The display is resizable (only applicable if combined with
ALLEGRO_WINDOWED).
+ALLEGRO_MAXIMIZED
+: The display window will be maximized (only applicable if combined
+ with ALLEGRO_RESIZABLE).
+ Since: 5.1.12
+
ALLEGRO_OPENGL
: Require the driver to provide an initialized OpenGL context after returning
successfully.
@@ -546,6 +551,7 @@ after creation are:
- ALLEGRO_FULLSCREEN_WINDOW
- ALLEGRO_FRAMELESS
+- ALLEGRO_MAXIMIZED
Returns true if the driver supports toggling the specified flag else
false. You can use [al_get_display_flags] to query whether the given
diff --git a/examples/ex_resize2.c b/examples/ex_resize2.c
index 8fa0bf2..7257d19 100644
--- a/examples/ex_resize2.c
+++ b/examples/ex_resize2.c
@@ -7,6 +7,7 @@
#include "allegro5/allegro.h"
#include "allegro5/allegro_image.h"
+#include "allegro5/allegro_font.h"
#include <stdio.h>
#include "common.c"
@@ -17,6 +18,7 @@ int main(int argc, char **argv)
ALLEGRO_BITMAP *bmp;
ALLEGRO_EVENT_QUEUE *queue;
ALLEGRO_EVENT event;
+ ALLEGRO_FONT *font;
bool redraw;
(void)argc;
@@ -27,6 +29,7 @@ int main(int argc, char **argv)
}
al_install_keyboard();
al_init_image_addon();
+ al_init_font_addon();
al_set_new_display_flags(ALLEGRO_RESIZABLE |
ALLEGRO_GENERATE_EXPOSE_EVENTS);
@@ -41,6 +44,8 @@ int main(int argc, char **argv)
abort_example("Unable to load image\n");
}
+ font = al_create_builtin_font();
+
queue = al_create_event_queue();
al_register_event_source(queue, al_get_display_event_source(display));
al_register_event_source(queue, al_get_keyboard_event_source());
@@ -53,6 +58,17 @@ int main(int argc, char **argv)
0, 0, al_get_bitmap_width(bmp), al_get_bitmap_height(bmp),
0, 0, al_get_display_width(display), al_get_display_height(display),
0);
+ al_draw_multiline_textf(font, al_map_rgb(255, 255, 0), 0, 0, 640,
+ al_get_font_line_height(font), 0,
+ "size: %d x %d\n"
+ "maximized: %s\n"
+ "+ key to maximize\n"
+ "- key to un-maximize",
+ al_get_display_width(display),
+ al_get_display_height(display),
+ al_get_display_flags(display) & ALLEGRO_MAXIMIZED ? "yes" :
+ "no");
+
al_flip_display();
redraw = false;
}
@@ -69,6 +85,14 @@ int main(int argc, char **argv)
event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
break;
}
+ if (event.type == ALLEGRO_EVENT_KEY_CHAR &&
+ event.keyboard.unichar == '+') {
+ al_set_display_flag(display, ALLEGRO_MAXIMIZED, true);
+ }
+ if (event.type == ALLEGRO_EVENT_KEY_CHAR &&
+ event.keyboard.unichar == '-') {
+ al_set_display_flag(display, ALLEGRO_MAXIMIZED, false);
+ }
if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
break;
}
diff --git a/include/allegro5/display.h b/include/allegro5/display.h
index 1d729cd..3171d2b 100644
--- a/include/allegro5/display.h
+++ b/include/allegro5/display.h
@@ -24,7 +24,8 @@ enum {
ALLEGRO_FULLSCREEN_WINDOW = 1 << 9,
ALLEGRO_MINIMIZED = 1 << 10,
ALLEGRO_PROGRAMMABLE_PIPELINE = 1 << 11,
- ALLEGRO_GTK_TOPLEVEL_INTERNAL = 1 << 12
+ ALLEGRO_GTK_TOPLEVEL_INTERNAL = 1 << 12,
+ ALLEGRO_MAXIMIZED = 1 << 13,
};
/* Possible parameters for al_set_display_option.
diff --git a/include/allegro5/internal/aintern_xwindow.h b/include/allegro5/internal/aintern_xwindow.h
index cf17fdd..b1c777f 100644
--- a/include/allegro5/internal/aintern_xwindow.h
+++ b/include/allegro5/internal/aintern_xwindow.h
@@ -8,6 +8,8 @@ void _al_xwin_set_above(ALLEGRO_DISPLAY *display, int value);
void _al_xwin_set_frame(ALLEGRO_DISPLAY *display, bool frame_on);
void _al_xwin_set_icons(ALLEGRO_DISPLAY *d,
int num_icons, ALLEGRO_BITMAP *bitmaps[]);
+void _al_xwin_maximize(ALLEGRO_DISPLAY *d, bool maximized);
+void _al_xwin_check_maximized(ALLEGRO_DISPLAY *display);
#endif
diff --git a/src/x/xdisplay.c b/src/x/xdisplay.c
index 6fb041e..572f5a0 100644
--- a/src/x/xdisplay.c
+++ b/src/x/xdisplay.c
@@ -409,6 +409,10 @@ static ALLEGRO_DISPLAY_XGLX *xdpy_create_display_locked(
}
}
+ if (display->flags & ALLEGRO_MAXIMIZED) {
+ _al_xwin_maximize(display, true);
+ }
+
if (!_al_xglx_config_create_context(d)) {
goto LateError;
}
@@ -803,6 +807,8 @@ static bool xdpy_acknowledge_resize(ALLEGRO_DISPLAY *d)
if (glx->context) {
_al_ogl_setup_gl(d);
}
+
+ _al_xwin_check_maximized(d);
}
_al_mutex_unlock(&system->lock);
@@ -993,6 +999,8 @@ void _al_xglx_display_configure(ALLEGRO_DISPLAY *d, int x, int y,
}
+ _al_xwin_check_maximized(d);
+
_al_event_source_unlock(es);
}
@@ -1272,6 +1280,9 @@ static bool xdpy_set_display_flag(ALLEGRO_DISPLAY *display, int flag,
case ALLEGRO_FULLSCREEN_WINDOW:
xdpy_set_fullscreen_window(display, flag_onoff);
return true;
+ case ALLEGRO_MAXIMIZED:
+ _al_xwin_maximize(display, flag_onoff);
+ return true;
}
return false;
}
diff --git a/src/x/xwindow.c b/src/x/xwindow.c
index d8c7132..4a71aa5 100644
--- a/src/x/xwindow.c
+++ b/src/x/xwindow.c
@@ -322,4 +322,68 @@ void _al_xwin_set_icons(ALLEGRO_DISPLAY *d,
}
+void _al_xwin_maximize(ALLEGRO_DISPLAY *display, bool maximized)
+{
+ if (!!(display->flags & ALLEGRO_MAXIMIZED) == maximized)
+ return;
+ ALLEGRO_SYSTEM_XGLX *system = (void *)al_get_system_driver();
+ ALLEGRO_DISPLAY_XGLX *glx = (ALLEGRO_DISPLAY_XGLX *)display;
+ Display *x11 = system->x11display;
+ int old_resize_count = glx->resize_count;
+
+ XEvent xev;
+ xev.xclient.type = ClientMessage;
+ xev.xclient.serial = 0;
+ xev.xclient.send_event = True;
+ xev.xclient.message_type = X11_ATOM(_NET_WM_STATE);
+ xev.xclient.window = glx->window;
+ xev.xclient.format = 32;
+
+ xev.xclient.data.l[0] = maximized ? 1 : 0;
+ xev.xclient.data.l[1] = X11_ATOM(_NET_WM_STATE_MAXIMIZED_HORZ);
+ xev.xclient.data.l[2] = X11_ATOM(_NET_WM_STATE_MAXIMIZED_VERT);
+ xev.xclient.data.l[3] = 0;
+
+ XSendEvent(
+ x11,
+ RootWindowOfScreen(ScreenOfDisplay(x11, glx->xscreen)),
+ False,
+ SubstructureRedirectMask | SubstructureNotifyMask, &xev);
+
+ _al_display_xglx_await_resize(display, old_resize_count, true);
+}
+
+
+void _al_xwin_check_maximized(ALLEGRO_DISPLAY *display)
+{
+ ALLEGRO_SYSTEM_XGLX *system = (void *)al_get_system_driver();
+ ALLEGRO_DISPLAY_XGLX *glx = (ALLEGRO_DISPLAY_XGLX *)display;
+ Display *x11 = system->x11display;
+ Atom type;
+ Atom horz = X11_ATOM(_NET_WM_STATE_MAXIMIZED_HORZ);
+ Atom vert = X11_ATOM(_NET_WM_STATE_MAXIMIZED_VERT);
+ Atom property = X11_ATOM(_NET_WM_STATE);
+ int format;
+ int maximized = 0;
+ unsigned long n, remaining, i, *p32;
+ unsigned char *p8 = NULL;
+ if (XGetWindowProperty(x11, glx->window, property, 0, INT_MAX,
+ False, AnyPropertyType, &type, &format, &n, &remaining, &p8)
+ != Success) {
+ return;
+ }
+ p32 = (unsigned long *)p8;
+ for (i = 0; i < n; i++) {
+ if (p32[i] == horz)
+ maximized |= 1;
+ if (p32[i] == vert)
+ maximized |= 2;
+ }
+ XFree(p8);
+ display->flags &= ~ALLEGRO_MAXIMIZED;
+ if (maximized == 3)
+ display->flags |= ALLEGRO_MAXIMIZED;
+}
+
+
/* vim: set sts=3 sw=3 et: */
--
2.1.4