Skip to content

Commit

Permalink
Rejig the system mutex lock for some X display functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
SiegeLordEx authored and SiegeLord committed Jan 9, 2024
1 parent 21a8907 commit 29cc1a8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
7 changes: 6 additions & 1 deletion addons/native_dialog/gtk_xgtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ static void xgtk_set_window_title(ALLEGRO_DISPLAY *display, const char *title)
}
}


/* [gtk thread] */
static gboolean do_set_fullscreen_window(gpointer data)
{
Expand Down Expand Up @@ -463,7 +462,9 @@ static bool xgtk_set_display_flag(ALLEGRO_DISPLAY *display, int flag, bool onoff
case ALLEGRO_FRAMELESS: {
if (!!(display->flags & ALLEGRO_FRAMELESS) == onoff)
return true;
ALLEGRO_SYSTEM_XGLX *system = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver();
ARGS_SET_FLAG args;
_al_mutex_lock(&system->lock);
if (_al_gtk_init_args(&args, sizeof(args))) {
args.display = (ALLEGRO_DISPLAY_XGLX *)display;
args.onoff = onoff;
Expand All @@ -473,12 +474,15 @@ static bool xgtk_set_display_flag(ALLEGRO_DISPLAY *display, int flag, bool onoff
else
display->flags &= ~ALLEGRO_FRAMELESS;
}
_al_mutex_unlock(&system->lock);
return true;
}
case ALLEGRO_MAXIMIZED: {
if (!!(display->flags & ALLEGRO_MAXIMIZED) == onoff)
return true;
ALLEGRO_SYSTEM_XGLX *system = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver();
ARGS_SET_FLAG args;
_al_mutex_lock(&system->lock);
if (_al_gtk_init_args(&args, sizeof(args))) {
args.display = (ALLEGRO_DISPLAY_XGLX *)display;
args.onoff = onoff;
Expand All @@ -487,6 +491,7 @@ static bool xgtk_set_display_flag(ALLEGRO_DISPLAY *display, int flag, bool onoff
_al_gtk_wait_for_args(do_maximize, &args);
_al_display_xglx_await_resize(display, old_resize_count, true);
}
_al_mutex_unlock(&system->lock);

return true;
}
Expand Down
19 changes: 13 additions & 6 deletions src/x/xdisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,9 @@ static void xdpy_apply_window_constraints(ALLEGRO_DISPLAY *display,
static void xdpy_set_fullscreen_window_default(ALLEGRO_DISPLAY *display, bool onoff)
{
if (onoff == !(display->flags & ALLEGRO_FULLSCREEN_WINDOW)) {
ALLEGRO_SYSTEM_XGLX *system = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver();
_al_mutex_lock(&system->lock);

_al_xwin_reset_size_hints(display);
_al_xwin_set_fullscreen_window(display, 2);
/* XXX Technically, the user may fiddle with the _NET_WM_STATE_FULLSCREEN
Expand All @@ -1383,6 +1386,8 @@ static void xdpy_set_fullscreen_window_default(ALLEGRO_DISPLAY *display, bool on
_al_xwin_set_size_hints(display, INT_MAX, INT_MAX);

set_compositor_bypass_flag(display);

_al_mutex_unlock(&system->lock);
}
}

Expand All @@ -1392,19 +1397,25 @@ static bool xdpy_set_display_flag_default(ALLEGRO_DISPLAY *display, int flag,
{
switch (flag) {
case ALLEGRO_FRAMELESS:
{
/* The ALLEGRO_FRAMELESS flag is backwards. */
_al_xwin_set_frame(display, !flag_onoff);
return true;
}
case ALLEGRO_FULLSCREEN_WINDOW:
{
/* Bypass system lock. */
ALLEGRO_DISPLAY_XGLX *glx = (ALLEGRO_DISPLAY_XGLX *)display;
glx->overridable_vt->set_fullscreen_window(display, flag_onoff);
return true;
}
case ALLEGRO_MAXIMIZED:
{
ALLEGRO_SYSTEM_XGLX *system = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver();
_al_mutex_lock(&system->lock);
_al_xwin_maximize(display, flag_onoff);
_al_mutex_unlock(&system->lock);
return true;
}
}
return false;
}
Expand All @@ -1413,11 +1424,7 @@ static bool xdpy_set_display_flag_default(ALLEGRO_DISPLAY *display, int flag,
static bool xdpy_set_display_flag(ALLEGRO_DISPLAY *display, int flag, bool onoff)
{
ALLEGRO_DISPLAY_XGLX *glx = (ALLEGRO_DISPLAY_XGLX *)display;
ALLEGRO_SYSTEM_XGLX *system = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver();
_al_mutex_lock(&system->lock);
bool ret = glx->overridable_vt->set_display_flag(display, flag, onoff);
_al_mutex_unlock(&system->lock);
return ret;
return glx->overridable_vt->set_display_flag(display, flag, onoff);
}


Expand Down
3 changes: 3 additions & 0 deletions src/x/xwindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ void _al_xwin_set_icons(ALLEGRO_DISPLAY *d,
}


/* Note: The system mutex must be locked (exactly once) before
* calling this as we call _al_display_xglx_await_resize.
*/
void _al_xwin_maximize(ALLEGRO_DISPLAY *display, bool maximized)
{
#ifndef ALLEGRO_RASPBERRYPI
Expand Down

0 comments on commit 29cc1a8

Please sign in to comment.