diff --git a/addons/native_dialog/gtk_xgtk.c b/addons/native_dialog/gtk_xgtk.c index c3cdc65d5..20481ca5b 100644 --- a/addons/native_dialog/gtk_xgtk.c +++ b/addons/native_dialog/gtk_xgtk.c @@ -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" @@ -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; @@ -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) { @@ -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); } @@ -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. */ diff --git a/examples/ex_windows.c b/examples/ex_windows.c index 91db60f18..ed51b6b8f 100644 --- a/examples/ex_windows.c +++ b/examples/ex_windows.c @@ -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]; @@ -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(); @@ -51,8 +60,8 @@ 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; @@ -60,8 +69,10 @@ int main(int argc, char **argv) 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; diff --git a/include/allegro5/internal/aintern_xwindow.h b/include/allegro5/internal/aintern_xwindow.h index 58e3d3da2..8ecc69644 100644 --- a/include/allegro5/internal/aintern_xwindow.h +++ b/include/allegro5/internal/aintern_xwindow.h @@ -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 diff --git a/src/x/xdisplay.c b/src/x/xdisplay.c index 614be834c..26039dcf5 100644 --- a/src/x/xdisplay.c +++ b/src/x/xdisplay.c @@ -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, @@ -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 void _al_xglx_display_configure(ALLEGRO_DISPLAY *d, int x, int y, int width, int height, bool setglxy) @@ -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 diff --git a/src/x/xwindow.c b/src/x/xwindow.c index 3ca717d31..b9dce4129 100644 --- a/src/x/xwindow.c +++ b/src/x/xwindow.c @@ -395,10 +395,10 @@ XID al_get_x_window_id(ALLEGRO_DISPLAY *display) ASSERT(display != NULL); return ((ALLEGRO_DISPLAY_XGLX*)display)->window; } - +#include // 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; @@ -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) { @@ -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"); } }