From 602e1368325d2cbfd6bd00940870bd4deb404c9e Mon Sep 17 00:00:00 2001 From: George Tokmaji Date: Fri, 22 Jan 2021 12:31:00 +0100 Subject: [PATCH] Move from GTK2 to GTK3 --- CMakeLists.txt | 9 ++++-- src/C4Console.cpp | 41 ++++++++------------------- src/C4Console.h | 2 +- src/C4DevmodeDlg.cpp | 5 ++-- src/C4DevmodeDlg.h | 3 +- src/C4EditCursor.cpp | 6 +--- src/C4EditCursor.h | 2 +- src/C4ObjectListDlg.cpp | 4 +-- src/C4ObjectListDlg.h | 4 +-- src/C4PropertyDlg.cpp | 8 ++---- src/C4PropertyDlg.h | 2 +- src/C4ToolsDlg.cpp | 44 ++++++++++++----------------- src/C4ToolsDlg.h | 2 +- src/C4Viewport.cpp | 61 ++++++++++++++++++++--------------------- src/C4WinMain.cpp | 3 +- src/StdGtkWindow.cpp | 25 +++++++++-------- src/StdGtkWindow.h | 2 +- 17 files changed, 94 insertions(+), 129 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index feff41f9c..ca958f1c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -336,11 +336,14 @@ if (NOT USE_CONSOLE) set(HAVE_FREETYPE 1) endif () -# Link GTK2 +# Link GTK3 if (WITH_DEVELOPER_MODE) set(WITH_GLIB 1) - find_package(GTK2 2.4 REQUIRED gtk) - target_link_libraries(clonk GTK2::gtk) + find_package(PkgConfig REQUIRED) + pkg_check_modules(GTK3 REQUIRED gtk+-3.0) + target_include_directories(clonk PRIVATE ${GTK3_INCLUDE_DIRS}) + target_link_libraries(clonk ${GTK3_LIBRARIES}) + target_compile_definitions(clonk PRIVATE GTK_DISABLE_SINGLE_INCLUDES GDK_DISABLE_DEPRECATED GSEAL_ENABLE) endif () # Link iconv diff --git a/src/C4Console.cpp b/src/C4Console.cpp index 6193769e3..a3ed28a69 100644 --- a/src/C4Console.cpp +++ b/src/C4Console.cpp @@ -66,24 +66,7 @@ namespace #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include @@ -404,9 +387,9 @@ GtkWidget *C4Console::InitGUI() gtk_container_add(GTK_CONTAINER(btnModeEdit), image_mode_edit); gtk_container_add(GTK_CONTAINER(btnModeDraw), image_mode_draw); - GtkWidget *top_hbox = gtk_hbox_new(FALSE, 18); - GtkWidget *play_hbox = gtk_hbox_new(FALSE, 6); - GtkWidget *mode_hbox = gtk_hbox_new(FALSE, 6); + GtkWidget *top_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 18); + GtkWidget *play_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); + GtkWidget *mode_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); gtk_box_pack_start(GTK_BOX(play_hbox), btnPlay, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(play_hbox), btnHalt, FALSE, TRUE, 0); @@ -423,7 +406,7 @@ GtkWidget *C4Console::InitGUI() // Statusbar - GtkWidget *statusbar = gtk_hbox_new(FALSE, 6); + GtkWidget *statusbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); GtkWidget *status_frame = gtk_frame_new(nullptr); gtk_frame_set_shadow_type(GTK_FRAME(status_frame), GTK_SHADOW_IN); @@ -437,8 +420,8 @@ GtkWidget *C4Console::InitGUI() gtk_misc_set_alignment(GTK_MISC(lblScript), 0.0, 0.5); gtk_misc_set_alignment(GTK_MISC(lblTime), 0.0, 0.5); - GtkWidget *sep1 = gtk_vseparator_new(); - GtkWidget *sep2 = gtk_vseparator_new(); + GtkWidget *sep1 = gtk_separator_new(GTK_ORIENTATION_VERTICAL); + GtkWidget *sep2 = gtk_separator_new(GTK_ORIENTATION_VERTICAL); gtk_box_pack_start(GTK_BOX(statusbar), lblFrame, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(statusbar), sep1, FALSE, FALSE, 0); @@ -544,8 +527,8 @@ GtkWidget *C4Console::InitGUI() // Window - GtkWidget *topbox = gtk_vbox_new(FALSE, 0); - GtkWidget *midbox = gtk_vbox_new(FALSE, 6); + GtkWidget *topbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + GtkWidget *midbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6); gtk_container_set_border_width(GTK_CONTAINER(midbox), 6); gtk_box_pack_start(GTK_BOX(midbox), scroll, TRUE, TRUE, 0); @@ -760,7 +743,7 @@ bool C4Console::SaveGame(bool fSaveGame) SetCursor(LoadCursor(0, IDC_WAIT)); #elif WITH_DEVELOPER_MODE // Seems not to work. Don't know why... - gdk_window_set_cursor(window->window, cursorWait); + gdk_window_set_cursor(gtk_widget_get_window(window), cursorWait); #endif C4GameSave *pGameSave; @@ -787,7 +770,7 @@ bool C4Console::SaveGame(bool fSaveGame) #ifdef _WIN32 SetCursor(LoadCursor(0, IDC_ARROW)); #elif WITH_DEVELOPER_MODE - gdk_window_set_cursor(window->window, nullptr); + gdk_window_set_cursor(gtk_widget_get_window(window), nullptr); #endif // Initialize/script notification @@ -1027,7 +1010,7 @@ bool C4Console::FileSelect(char *sFilename, int iSize, const char *szFilter, uin SetCurrentDirectory(Config.General.ExePath); return fResult; #elif WITH_DEVELOPER_MODE - GtkWidget *dialog = gtk_file_chooser_dialog_new(fSave ? "Save file..." : "Load file...", GTK_WINDOW(window), fSave ? GTK_FILE_CHOOSER_ACTION_SAVE : GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, fSave ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, nullptr); + GtkWidget *dialog = gtk_file_chooser_dialog_new(fSave ? "Save file..." : "Load file...", GTK_WINDOW(window), fSave ? GTK_FILE_CHOOSER_ACTION_SAVE : GTK_FILE_CHOOSER_ACTION_OPEN, "format-text-bold", GTK_RESPONSE_CANCEL, fSave ? "document-save" : "document-open", GTK_RESPONSE_ACCEPT, nullptr); // TODO: Set dialog modal? diff --git a/src/C4Console.h b/src/C4Console.h index bdb337f7c..98280fa45 100644 --- a/src/C4Console.h +++ b/src/C4Console.h @@ -27,7 +27,7 @@ #include #ifdef WITH_DEVELOPER_MODE -#include +#include #endif const int C4CNS_ModePlay = 0, diff --git a/src/C4DevmodeDlg.cpp b/src/C4DevmodeDlg.cpp index d7567b4ab..f1491aab5 100644 --- a/src/C4DevmodeDlg.cpp +++ b/src/C4DevmodeDlg.cpp @@ -23,8 +23,7 @@ #include -#include -#include +#include GtkWidget *C4DevmodeDlg::window = nullptr; GtkWidget *C4DevmodeDlg::notebook = nullptr; @@ -90,7 +89,7 @@ void C4DevmodeDlg::RemovePage(GtkWidget *widget) void C4DevmodeDlg::SwitchPage(GtkWidget *widget) { - bool is_visible = GTK_WIDGET_VISIBLE(GTK_WIDGET(window)); + bool is_visible = gtk_widget_get_visible(GTK_WIDGET(window)); // Remember window position if (window != nullptr && is_visible) diff --git a/src/C4DevmodeDlg.h b/src/C4DevmodeDlg.h index 716f4666f..bbe9f984a 100644 --- a/src/C4DevmodeDlg.h +++ b/src/C4DevmodeDlg.h @@ -20,8 +20,7 @@ #pragma once #ifdef WITH_DEVELOPER_MODE -#include -#include +#include #endif // WITH_DEVELOPER_MODE // TODO: Threadsafety? diff --git a/src/C4EditCursor.cpp b/src/C4EditCursor.cpp index ef1e7d42e..580a4cf5c 100644 --- a/src/C4EditCursor.cpp +++ b/src/C4EditCursor.cpp @@ -31,11 +31,7 @@ #ifdef WITH_DEVELOPER_MODE #include -#include -#include -#include -#include -#include +#include #endif C4EditCursor::C4EditCursor() diff --git a/src/C4EditCursor.h b/src/C4EditCursor.h index 351273b4e..b7574f519 100644 --- a/src/C4EditCursor.h +++ b/src/C4EditCursor.h @@ -22,7 +22,7 @@ #include "C4Control.h" #ifdef WITH_DEVELOPER_MODE -#include +#include #endif class C4EditCursor diff --git a/src/C4ObjectListDlg.cpp b/src/C4ObjectListDlg.cpp index a4e485037..f5b0a930e 100644 --- a/src/C4ObjectListDlg.cpp +++ b/src/C4ObjectListDlg.cpp @@ -25,8 +25,6 @@ #ifdef WITH_DEVELOPER_MODE #include -#include -#include /* Some boilerplate GObject defines. 'klass' is used instead of 'class', because 'class' is a C++ keyword */ @@ -745,7 +743,7 @@ void C4ObjectListDlg::Open() g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(OnDestroy), this); // The VBox and Tree - GtkWidget *vbox = gtk_vbox_new(FALSE, 8); + GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); GtkWidget *scrolled_wnd = gtk_scrolled_window_new(nullptr, nullptr); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_wnd), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); diff --git a/src/C4ObjectListDlg.h b/src/C4ObjectListDlg.h index f048b116d..2e0b16a58 100644 --- a/src/C4ObjectListDlg.h +++ b/src/C4ObjectListDlg.h @@ -20,9 +20,7 @@ #pragma once #ifdef WITH_DEVELOPER_MODE -#include -#include -#include +#include #endif // WITH_DEVELOPER_MODE #include "C4ObjectList.h" diff --git a/src/C4PropertyDlg.cpp b/src/C4PropertyDlg.cpp index 631476f2a..4903dd3f5 100644 --- a/src/C4PropertyDlg.cpp +++ b/src/C4PropertyDlg.cpp @@ -33,11 +33,7 @@ #include #include -#include -#include -#include -#include -#include +#include #endif #ifdef _WIN32 @@ -121,7 +117,7 @@ bool C4PropertyDlg::Open() #ifdef WITH_DEVELOPER_MODE if (vbox == nullptr) { - vbox = gtk_vbox_new(FALSE, 6); + vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6); GtkWidget *scrolled_wnd = gtk_scrolled_window_new(nullptr, nullptr); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_wnd), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); diff --git a/src/C4PropertyDlg.h b/src/C4PropertyDlg.h index 147c7f8ce..327cc8bf7 100644 --- a/src/C4PropertyDlg.h +++ b/src/C4PropertyDlg.h @@ -21,7 +21,7 @@ #include "C4ObjectList.h" #ifdef WITH_DEVELOPER_MODE -#include +#include #endif class C4PropertyDlg diff --git a/src/C4ToolsDlg.cpp b/src/C4ToolsDlg.cpp index 562e70bd3..c02d43d34 100644 --- a/src/C4ToolsDlg.cpp +++ b/src/C4ToolsDlg.cpp @@ -35,14 +35,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include @@ -284,8 +276,8 @@ bool C4ToolsDlg::Open() #elif defined(WITH_DEVELOPER_MODE) if (hbox == nullptr) { - hbox = gtk_hbox_new(FALSE, 12); - GtkWidget *vbox = gtk_vbox_new(FALSE, 6); + hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12); + GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6); GtkWidget *image_brush = CreateImageFromInlinedPixbuf(brush_pixbuf_data); GtkWidget *image_line = CreateImageFromInlinedPixbuf(line_pixbuf_data); @@ -313,9 +305,9 @@ bool C4ToolsDlg::Open() gtk_box_pack_start(GTK_BOX(vbox), landscape_exact, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); - vbox = gtk_vbox_new(FALSE, 12); + vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12); gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0); - GtkWidget *local_hbox = gtk_hbox_new(FALSE, 6); + GtkWidget *local_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); brush = gtk_toggle_button_new(); line = gtk_toggle_button_new(); @@ -336,16 +328,16 @@ bool C4ToolsDlg::Open() gtk_box_pack_start(GTK_BOX(local_hbox), picker, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), local_hbox, FALSE, FALSE, 0); - local_hbox = gtk_hbox_new(FALSE, 12); + local_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12); gtk_box_pack_start(GTK_BOX(vbox), local_hbox, TRUE, TRUE, 0); preview = gtk_image_new(); gtk_box_pack_start(GTK_BOX(local_hbox), preview, FALSE, FALSE, 0); - scale = gtk_vscale_new(nullptr); + scale = gtk_scale_new(GTK_ORIENTATION_VERTICAL, nullptr); gtk_box_pack_start(GTK_BOX(local_hbox), scale, FALSE, FALSE, 0); - vbox = gtk_vbox_new(FALSE, 6); + vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6); ift = gtk_toggle_button_new(); no_ift = gtk_toggle_button_new(); @@ -358,10 +350,10 @@ bool C4ToolsDlg::Open() gtk_box_pack_start(GTK_BOX(local_hbox), vbox, FALSE, FALSE, 0); - vbox = gtk_vbox_new(FALSE, 6); + vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6); - materials = gtk_combo_box_new_text(); - textures = gtk_combo_box_new_text(); + materials = gtk_combo_box_text_new(); + textures = gtk_combo_box_text_new(); gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(materials), RowSeparatorFunc, nullptr, nullptr); gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(textures), RowSeparatorFunc, nullptr, nullptr); @@ -491,10 +483,10 @@ void C4ToolsDlg::InitMaterialCtrls() g_signal_handler_block(materials, handlerMaterials); gtk_list_store_clear(list); - gtk_combo_box_append_text(GTK_COMBO_BOX(materials), C4TLS_MatSky); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(materials), C4TLS_MatSky); for (int32_t cnt = 0; cnt < Game.Material.Num; cnt++) { - gtk_combo_box_append_text(GTK_COMBO_BOX(materials), Game.Material.Map[cnt].Name); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(materials), Game.Material.Map[cnt].Name); } g_signal_handler_unblock(materials, handlerMaterials); SelectComboBoxText(GTK_COMBO_BOX(materials), Material); @@ -523,7 +515,7 @@ void C4ToolsDlg::UpdateTextures() #ifdef _WIN32 SendDlgItemMessage(hDialog, IDC_COMBOTEXTURE, CB_INSERTSTRING, 0, reinterpret_cast(szTexture)); #elif defined(WITH_DEVELOPER_MODE) - gtk_combo_box_prepend_text(GTK_COMBO_BOX(textures), szTexture); + gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(textures), szTexture); #endif } } @@ -533,7 +525,7 @@ void C4ToolsDlg::UpdateTextures() #ifdef _WIN32 SendDlgItemMessage(hDialog, IDC_COMBOTEXTURE, CB_INSERTSTRING, 0, reinterpret_cast("-------")); #elif defined(WITH_DEVELOPER_MODE) - gtk_combo_box_prepend_text(GTK_COMBO_BOX(textures), "-------"); + gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(textures), "-------"); #endif } @@ -546,7 +538,7 @@ void C4ToolsDlg::UpdateTextures() #ifdef _WIN32 SendDlgItemMessage(hDialog, IDC_COMBOTEXTURE, CB_INSERTSTRING, 0, reinterpret_cast(szTexture)); #elif defined(WITH_DEVELOPER_MODE) - gtk_combo_box_prepend_text(GTK_COMBO_BOX(textures), szTexture); + gtk_combo_box_text_prepend_text(GTK_COMBO_BOX_TEXT(textures), szTexture); #endif } } @@ -667,7 +659,7 @@ void C4ToolsDlg::UpdatePreview() #ifdef _WIN32 if (IsWindowEnabled(GetDlgItem(hDialog, IDC_PREVIEW))) #elif defined(WITH_DEVELOPER_MODE) - if (GTK_WIDGET_SENSITIVE(preview)) + if (gtk_widget_get_sensitive(preview)) #endif Application.DDraw->DrawPatternedCircle(surfacePreview.get(), previewWidth / 2, previewHeight / 2, @@ -1043,14 +1035,14 @@ void C4ToolsDlg::OnButtonNoIft(GtkWidget *widget, gpointer data) void C4ToolsDlg::OnComboMaterial(GtkWidget *widget, gpointer data) { - gchar *text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(widget)); + gchar *text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widget)); static_cast(data)->SetMaterial(text); g_free(text); } void C4ToolsDlg::OnComboTexture(GtkWidget *widget, gpointer data) { - gchar *text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(widget)); + gchar *text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widget)); static_cast(data)->SetTexture(text); g_free(text); } diff --git a/src/C4ToolsDlg.h b/src/C4ToolsDlg.h index 1ac0b6dd1..ed061f35b 100644 --- a/src/C4ToolsDlg.h +++ b/src/C4ToolsDlg.h @@ -27,7 +27,7 @@ #endif #ifdef WITH_DEVELOPER_MODE -#include +#include #endif const int32_t C4TLS_Brush = 0, diff --git a/src/C4Viewport.cpp b/src/C4Viewport.cpp index 54854b9f9..680716a51 100644 --- a/src/C4Viewport.cpp +++ b/src/C4Viewport.cpp @@ -46,12 +46,7 @@ #ifdef WITH_DEVELOPER_MODE #include #include -#include -#include -#include -#include -#include -#include +#include #endif #endif @@ -311,14 +306,14 @@ GtkWidget *C4ViewportWindow::InitGUI() GtkWidget *table; drawing_area = gtk_drawing_area_new(); - h_scrollbar = gtk_hscrollbar_new(nullptr); - v_scrollbar = gtk_vscrollbar_new(nullptr); + h_scrollbar = gtk_scrollbar_new(GTK_ORIENTATION_HORIZONTAL, nullptr); + v_scrollbar = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, nullptr); table = gtk_table_new(2, 2, FALSE); GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(h_scrollbar)); - adjustment->lower = 0; - adjustment->upper = GBackWdt; - adjustment->step_increment = ViewportScrollSpeed; + gtk_adjustment_set_lower(adjustment, 0); + gtk_adjustment_set_upper(adjustment, GBackWdt); + gtk_adjustment_set_step_increment(adjustment, ViewportScrollSpeed); g_signal_connect( G_OBJECT(adjustment), @@ -328,9 +323,9 @@ GtkWidget *C4ViewportWindow::InitGUI() ); adjustment = gtk_range_get_adjustment(GTK_RANGE(v_scrollbar)); - adjustment->lower = 0; - adjustment->upper = GBackHgt; - adjustment->step_increment = ViewportScrollSpeed; + gtk_adjustment_set_lower(adjustment, 0); + gtk_adjustment_set_upper(adjustment, GBackHgt); + gtk_adjustment_set_step_increment(adjustment, ViewportScrollSpeed); g_signal_connect( G_OBJECT(adjustment), @@ -391,16 +386,18 @@ bool C4Viewport::ScrollBarsByViewPosition() { if (PlayerLock) return false; + GtkAllocation allocation; + gtk_widget_get_allocation(pWindow->drawing_area, &allocation); GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(pWindow->h_scrollbar)); - adjustment->page_increment = pWindow->drawing_area->allocation.width; - adjustment->page_size = pWindow->drawing_area->allocation.width; - adjustment->value = ViewX; + gtk_adjustment_set_page_increment(adjustment, allocation.width); + gtk_adjustment_set_page_size(adjustment, allocation.width); + gtk_adjustment_set_value(adjustment, ViewX); gtk_adjustment_changed(adjustment); adjustment = gtk_range_get_adjustment(GTK_RANGE(pWindow->v_scrollbar)); - adjustment->page_increment = pWindow->drawing_area->allocation.height; - adjustment->page_size = pWindow->drawing_area->allocation.height; - adjustment->value = ViewY; + gtk_adjustment_set_page_increment(adjustment, allocation.height); + gtk_adjustment_set_page_size(adjustment, allocation.height); + gtk_adjustment_set_value(adjustment, ViewY); gtk_adjustment_changed(adjustment); return true; @@ -411,10 +408,10 @@ bool C4Viewport::ViewPositionByScrollBars() if (PlayerLock) return false; GtkAdjustment *adjustment = gtk_range_get_adjustment(GTK_RANGE(pWindow->h_scrollbar)); - ViewX = static_cast(adjustment->value); + ViewX = static_cast(gtk_adjustment_get_value(adjustment)); adjustment = gtk_range_get_adjustment(GTK_RANGE(pWindow->v_scrollbar)); - ViewY = static_cast(adjustment->value); + ViewY = static_cast(gtk_adjustment_get_value(adjustment)); return true; } @@ -461,15 +458,15 @@ void C4ViewportWindow::OnRealizeStatic(GtkWidget *widget, gpointer user_data) gboolean C4ViewportWindow::OnKeyPressStatic(GtkWidget *widget, GdkEventKey *event, gpointer user_data) { - if (event->keyval == GDK_Scroll_Lock) + if (event->keyval == GDK_KEY_Scroll_Lock) static_cast(user_data)->cvp->TogglePlayerLock(); #ifndef NDEBUG switch (event->keyval) { - case GDK_1: Config.Graphics.BlitOffset -= 0.05; printf("%f\n", Config.Graphics.BlitOffset); break; - case GDK_2: Config.Graphics.BlitOffset += 0.05; printf("%f\n", Config.Graphics.BlitOffset); break; - case GDK_3: Config.Graphics.TexIndent -= 0.05; printf("%f\n", Config.Graphics.TexIndent); break; - case GDK_4: Config.Graphics.TexIndent += 0.05; printf("%f\n", Config.Graphics.TexIndent); break; + case GDK_KEY_1: Config.Graphics.BlitOffset -= 0.05; printf("%f\n", Config.Graphics.BlitOffset); break; + case GDK_KEY_2: Config.Graphics.BlitOffset += 0.05; printf("%f\n", Config.Graphics.BlitOffset); break; + case GDK_KEY_3: Config.Graphics.TexIndent -= 0.05; printf("%f\n", Config.Graphics.TexIndent); break; + case GDK_KEY_4: Config.Graphics.TexIndent += 0.05; printf("%f\n", Config.Graphics.TexIndent); break; } #endif uint32_t key = XkbKeycodeToKeysym(GDK_WINDOW_XDISPLAY(event->window), event->hardware_keycode, 0, 0); @@ -788,11 +785,13 @@ bool C4Viewport::UpdateOutputSize() // Output size C4Rect rect; #ifdef WITH_DEVELOPER_MODE + GtkAllocation allocation; + gtk_widget_get_allocation(pWindow->drawing_area, &allocation); // Use only size of drawing area without scrollbars - rect.x = pWindow->drawing_area->allocation.x; - rect.y = pWindow->drawing_area->allocation.y; - rect.Wdt = pWindow->drawing_area->allocation.width; - rect.Hgt = pWindow->drawing_area->allocation.height; + rect.x = allocation.x; + rect.y = allocation.y; + rect.Wdt = allocation.x + allocation.width; + rect.Hgt = allocation.y + allocation.height; #else if (!pWindow->GetSize(rect)) return false; #endif diff --git a/src/C4WinMain.cpp b/src/C4WinMain.cpp index ee660d910..9aed19a3a 100644 --- a/src/C4WinMain.cpp +++ b/src/C4WinMain.cpp @@ -24,8 +24,7 @@ #include #ifdef WITH_DEVELOPER_MODE -#include -#include +#include #endif // debug memory management diff --git a/src/StdGtkWindow.cpp b/src/StdGtkWindow.cpp index b318fc277..897597b83 100644 --- a/src/StdGtkWindow.cpp +++ b/src/StdGtkWindow.cpp @@ -22,9 +22,10 @@ #include "res/lc.xpm" #include +#include #include #include -#include +#include /* CStdGtkWindow */ @@ -52,7 +53,7 @@ bool CStdGtkWindow::Init(CStdApp *const app, const char *const title, const C4Re GtkWidget *render_widget = InitGUI(); - gtk_widget_set_colormap(render_widget, gdk_colormap_new(gdkx_visual_get(((XVisualInfo *)Info)->visualid), TRUE)); + gtk_widget_set_visual(render_widget, gdk_x11_screen_lookup_visual(gtk_window_get_screen(GTK_WINDOW(window)), static_cast(Info)->visualid)); gtk_widget_show_all(window); @@ -62,30 +63,32 @@ bool CStdGtkWindow::Init(CStdApp *const app, const char *const title, const C4Re gtk_window_set_title(GTK_WINDOW(window), title); + auto *gdkWindow = gtk_widget_get_window(window); + // Wait until window is mapped to get the window's XID gtk_widget_show_now(window); - wnd = GDK_WINDOW_XWINDOW(window->window); - gdk_window_add_filter(window->window, OnFilter, this); + wnd = gdk_x11_window_get_xid(gdkWindow); + gdk_window_add_filter(gdkWindow, OnFilter, this); XWMHints *wm_hint = XGetWMHints(dpy, wnd); if (!wm_hint) wm_hint = XAllocWMHints(); Hints = wm_hint; if (GTK_IS_LAYOUT(render_widget)) - renderwnd = GDK_WINDOW_XWINDOW(GTK_LAYOUT(render_widget)->bin_window); + renderwnd = gdk_x11_window_get_xid(gtk_layout_get_bin_window(GTK_LAYOUT(render_widget))); else - renderwnd = GDK_WINDOW_XWINDOW(render_widget->window); + renderwnd = gdk_x11_window_get_xid(gtk_widget_get_window(render_widget)); if (parent) XSetTransientForHint(dpy, wnd, parent->wnd); if (HideCursor()) { - gdk_window_set_cursor(window->window, nullptr); + gdk_window_set_cursor(gdkWindow, nullptr); } // Make sure the window is shown and ready to be rendered into, // this avoids an async X error. - gdk_flush(); + gdk_display_flush(gdk_display_get_default()); Active = true; return true; @@ -145,9 +148,9 @@ gboolean CStdGtkWindow::OnUpdateKeyMask(GtkWidget *widget, GdkEventKey *event, g // For keypress/relases, event->state contains the state _before_ // the event, but we need to store the current state. - if (event->keyval == GDK_Shift_L || event->keyval == GDK_Shift_R) mask ^= MK_SHIFT; - if (event->keyval == GDK_Control_L || event->keyval == GDK_Control_R) mask ^= MK_CONTROL; - if (event->keyval == GDK_Alt_L || event->keyval == GDK_Alt_R) mask ^= (1 << 3); + if (event->keyval == GDK_KEY_Shift_L || event->keyval == GDK_KEY_Shift_R) mask ^= MK_SHIFT; + if (event->keyval == GDK_KEY_Control_L || event->keyval == GDK_KEY_Control_R) mask ^= MK_CONTROL; + if (event->keyval == GDK_KEY_Alt_L || event->keyval == GDK_KEY_Alt_R) mask ^= (1 << 3); static_cast(user_data)->KeyMask = mask; return FALSE; diff --git a/src/StdGtkWindow.h b/src/StdGtkWindow.h index c18f9f7e2..7634f796c 100644 --- a/src/StdGtkWindow.h +++ b/src/StdGtkWindow.h @@ -21,7 +21,7 @@ #include -#include +#include class CStdGtkWindow : public CStdWindow {