Skip to content

Commit

Permalink
GTK borders WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
SiegeLord committed Nov 11, 2023
1 parent 549f189 commit 6841840
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
11 changes: 10 additions & 1 deletion addons/native_dialog/gtk_xgtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "allegro5/internal/aintern_xdisplay.h"
#include "allegro5/internal/aintern_xevents.h"
#include "allegro5/internal/aintern_xsystem.h"
#include "allegro5/internal/aintern_xwindow.h"

#include "gtk_dialog.h"
#include "gtk_xgtk.h"
Expand All @@ -23,6 +24,8 @@ typedef struct ARGS_CREATE
ALLEGRO_DISPLAY_XGLX *display;
int w;
int h;
int init_x;
int init_y;
const char *title;
} ARGS_CREATE;

Expand Down Expand Up @@ -115,6 +118,9 @@ static gboolean do_create_display_hook(gpointer data)

gtk_window_set_title(GTK_WINDOW(window), args->title);

if (args->init_x != INT_MAX && args->init_y != INT_MAX)
gtk_window_move(GTK_WINDOW(window), args->init_x, args->init_y);

gtk_widget_show_all(window);

if (display->flags & ALLEGRO_RESIZABLE) {
Expand Down Expand Up @@ -164,6 +170,7 @@ static bool xgtk_create_display_hook(ALLEGRO_DISPLAY *display, int w, int h)
args.w = w;
args.h = h;
args.title = al_get_new_window_title();
al_get_new_window_position(&args.init_x, &args.init_y);

return _al_gtk_wait_for_args(do_create_display_hook, &args);
}
Expand All @@ -185,7 +192,9 @@ static gboolean xgtk_handle_configure_event(GtkWidget *widget,
ALLEGRO_DISPLAY_XGLX *d = (ALLEGRO_DISPLAY_XGLX *)display;
(void)widget;
(void)event;

printf("GTK configure\n"); fflush(stdout);
GdkWindow *gdk_window = gtk_widget_get_window(d->gtk->gtkwindow);
_al_xwin_get_borders(display, gdk_x11_window_get_xid(gdk_window));
/* Update our idea of the window position.
* event->x, event->y is incorrect.
*/
Expand Down
19 changes: 15 additions & 4 deletions examples/ex_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
const int W = 400;
const int H = 200;


ALLEGRO_MENU_INFO main_menu_info[] = {
ALLEGRO_START_OF_MENU("&File", 3),
{ "&Open", 1, 0, NULL },
ALLEGRO_MENU_SEPARATOR,
{ "E&xit", 2, 0, NULL },
ALLEGRO_END_OF_MENU,
ALLEGRO_END_OF_MENU,
};

int main(int argc, char **argv)
{
ALLEGRO_DISPLAY *displays[2];
Expand All @@ -33,6 +41,7 @@ int main(int argc, char **argv)

al_install_mouse();
al_install_keyboard();
al_init_native_dialog_addon();
al_init_font_addon();
open_log();

Expand All @@ -51,17 +60,19 @@ int main(int argc, char **argv)

// center the first window
ALLEGRO_MONITOR_INFO init_info = info[0];
x = (init_info.x1 + init_info.x2 - W) / 2;
y = (init_info.y1 + init_info.y2 - H) / 2;
x = 100;//(init_info.x1 + init_info.x2 - W) / 2;
y = 200;//(init_info.y1 + init_info.y2 - H) / 2;
jump_x[0] = x;
jump_y[0] = y;
jump_adapter[0] = 0;

al_set_new_window_position(x, y);
al_set_new_window_title("Window 1");

al_set_new_display_flags(ALLEGRO_RESIZABLE);
al_set_new_display_flags(ALLEGRO_RESIZABLE | ALLEGRO_GTK_TOPLEVEL);
displays[0] = al_create_display(W, H);
ALLEGRO_MENU *menu = al_build_menu(main_menu_info);
al_set_display_menu(displays[0], menu);

// use the default position for the second window
jump_x[1] = INT_MAX;
Expand Down
2 changes: 1 addition & 1 deletion include/allegro5/internal/aintern_xwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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);
void _al_xwin_get_borders(ALLEGRO_DISPLAY *display);
void _al_xwin_get_borders(ALLEGRO_DISPLAY *display, Window w);

#endif

Expand Down
6 changes: 4 additions & 2 deletions src/x/xdisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ static bool xdpy_create_display_window(ALLEGRO_SYSTEM_XGLX *system,
}
}

printf("x_off/y_off: %d %d\n", x_off, y_off); fflush(stdout);
d->window = XCreateWindow(system->x11display,
RootWindow(system->x11display, d->xvinfo->screen),
x_off != INT_MAX ? x_off : 0,
Expand Down Expand Up @@ -1032,7 +1033,7 @@ static bool xdpy_resize_display(ALLEGRO_DISPLAY *d, int w, int h)

return glx->overridable_vt->resize_display(d, w, h);
}

#include <stdio.h>

void _al_xglx_display_configure(ALLEGRO_DISPLAY *d, int x, int y,
int width, int height, bool setglxy)
Expand All @@ -1042,7 +1043,8 @@ void _al_xglx_display_configure(ALLEGRO_DISPLAY *d, int x, int y,
ALLEGRO_EVENT_SOURCE *es = &glx->display.es;
_al_event_source_lock(es);

_al_xwin_get_borders(d);
_al_xwin_get_borders(d, glx->window);
printf("Here\n"); fflush(stdout);

/* Generate a resize event if the size has changed non-programmatically.
* We cannot asynchronously change the display size here yet, since the user
Expand Down
10 changes: 7 additions & 3 deletions src/x/xwindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,10 @@ XID al_get_x_window_id(ALLEGRO_DISPLAY *display)
ASSERT(display != NULL);
return ((ALLEGRO_DISPLAY_XGLX*)display)->window;
}

#include <stdio.h>

// Note: this only seems to work after the window has been mapped
void _al_xwin_get_borders(ALLEGRO_DISPLAY *display) {
void _al_xwin_get_borders(ALLEGRO_DISPLAY *display, Window window) {
ALLEGRO_DISPLAY_XGLX *glx = (ALLEGRO_DISPLAY_XGLX *)display;
ALLEGRO_SYSTEM_XGLX *system = (void *)al_get_system_driver();
Display *x11 = system->x11display;
Expand All @@ -408,7 +408,8 @@ void _al_xwin_get_borders(ALLEGRO_DISPLAY *display) {
unsigned long nitems, bytes_after;
unsigned char *property;
Atom frame_extents = X11_ATOM(_NET_FRAME_EXTENTS);
if (XGetWindowProperty(x11, glx->window,
printf("XID: %x\n", window); fflush(stdout);
if (XGetWindowProperty(x11, window,
frame_extents, 0, 16, 0, XA_CARDINAL,
&type, &format, &nitems, &bytes_after, &property) == Success) {
if (type != None && nitems == 4) {
Expand All @@ -417,15 +418,18 @@ void _al_xwin_get_borders(ALLEGRO_DISPLAY *display) {
glx->border_top = (int)((long *)property)[2];
glx->border_bottom = (int)((long *)property)[3];
glx->borders_known = true;
printf("Got extents\n"); fflush(stdout);
ALLEGRO_DEBUG("_NET_FRAME_EXTENTS: %d %d %d %d\n", glx->border_left, glx->border_top,
glx->border_right, glx->border_bottom);
}
else {
printf("Unexpected %lu\n", nitems); fflush(stdout);
ALLEGRO_DEBUG("Unexpected _NET_FRAME_EXTENTS format: nitems=%lu\n", nitems);
}
XFree(property);
}
else {
printf("Could not read\n"); fflush(stdout);
ALLEGRO_DEBUG("Could not read _NET_FRAME_EXTENTS\n");
}
}
Expand Down

0 comments on commit 6841840

Please sign in to comment.