| 75 // delay exit handler |
75 // delay exit handler |
| 76 g_idle_add(ui_window_destroy, data); |
76 g_idle_add(ui_window_destroy, data); |
| 77 } |
77 } |
| 78 |
78 |
| 79 static gboolean ui_window_close_request(UiObject *obj) { |
79 static gboolean ui_window_close_request(UiObject *obj) { |
| |
80 if(obj->widget) { |
| |
81 void *appwindow = g_object_get_data(G_OBJECT(obj->widget), "ui.appwindow"); |
| |
82 if(appwindow) { |
| |
83 int width = 0; |
| |
84 int height = 0; |
| |
85 #if GTK_CHECK_VERSION(4, 10, 0) |
| |
86 graphene_rect_t bounds; |
| |
87 if(gtk_widget_compute_bounds(obj->widget, obj->widget, &bounds)) { |
| |
88 width = bounds.size.width; |
| |
89 height = bounds.size.height; |
| |
90 } |
| |
91 #elif GTK_CHECK_VERSION(4, 0, 0) |
| |
92 GtkAllocation alloc; |
| |
93 gtk_widget_get_allocation(GTK_WIDGET(obj->widget), &alloc); |
| |
94 width = alloc.width; |
| |
95 height = alloc.height; |
| |
96 #else |
| |
97 gtk_window_get_size(GTK_WINDOW(obj->widget), &width, &height); |
| |
98 #endif |
| |
99 if(width > 0 && height > 0) { |
| |
100 char width_str[32]; |
| |
101 char height_str[32]; |
| |
102 snprintf(width_str, 32, "%d", width); |
| |
103 snprintf(height_str, 32, "%d", height); |
| |
104 ui_set_property("ui.window.width", width_str); |
| |
105 ui_set_property("ui.window.height", height_str); |
| |
106 } |
| |
107 } |
| |
108 } |
| |
109 |
| 80 uic_context_prepare_close(obj->ctx); |
110 uic_context_prepare_close(obj->ctx); |
| 81 obj->ref--; |
111 obj->ref--; |
| 82 if(obj->ref > 0) { |
112 if(obj->ref > 0) { |
| 83 #if GTK_CHECK_VERSION(2, 18, 0) |
113 #if GTK_CHECK_VERSION(2, 18, 0) |
| 84 gtk_widget_set_visible(obj->widget, FALSE); |
114 gtk_widget_set_visible(obj->widget, FALSE); |
| 120 |
150 |
| 121 if(title != NULL) { |
151 if(title != NULL) { |
| 122 gtk_window_set_title(GTK_WINDOW(obj->widget), title); |
152 gtk_window_set_title(GTK_WINDOW(obj->widget), title); |
| 123 } |
153 } |
| 124 |
154 |
| 125 const char *width = ui_get_property("ui.window.width"); |
155 if(!simple) { |
| 126 const char *height = ui_get_property("ui.window.height"); |
156 g_object_set_data(G_OBJECT(obj->widget), "ui.appwindow", obj); |
| 127 if(width && height) { |
157 } |
| 128 gtk_window_set_default_size( |
158 |
| |
159 int window_width = window_default_width; |
| |
160 int window_height = window_default_height; |
| |
161 if(!simple) { |
| |
162 const char *width = ui_get_property("ui.window.width"); |
| |
163 const char *height = ui_get_property("ui.window.height"); |
| |
164 if(width && height) { |
| |
165 int w = atoi(width); |
| |
166 int h = atoi(height); |
| |
167 if(w > 0 && h > 0) { |
| |
168 window_width = w; |
| |
169 window_height = h; |
| |
170 } |
| |
171 } |
| |
172 } |
| |
173 gtk_window_set_default_size( |
| 129 GTK_WINDOW(obj->widget), |
174 GTK_WINDOW(obj->widget), |
| 130 atoi(width), |
175 window_width, |
| 131 atoi(height)); |
176 window_height); |
| 132 } else { |
|
| 133 gtk_window_set_default_size( |
|
| 134 GTK_WINDOW(obj->widget), |
|
| 135 window_default_width + sidebar*250, |
|
| 136 window_default_height); |
|
| 137 } |
|
| 138 |
177 |
| 139 obj->destroy = ui_window_widget_destroy; |
178 obj->destroy = ui_window_widget_destroy; |
| 140 g_signal_connect( |
179 g_signal_connect( |
| 141 obj->widget, |
180 obj->widget, |
| 142 "destroy", |
181 "destroy", |
| 159 GtkWidget *vbox = ui_gtk_vbox_new(0); |
198 GtkWidget *vbox = ui_gtk_vbox_new(0); |
| 160 #ifdef UI_LIBADWAITA |
199 #ifdef UI_LIBADWAITA |
| 161 GtkWidget *toolbar_view = adw_toolbar_view_new(); |
200 GtkWidget *toolbar_view = adw_toolbar_view_new(); |
| 162 adw_toolbar_view_set_content(ADW_TOOLBAR_VIEW(toolbar_view), vbox); |
201 adw_toolbar_view_set_content(ADW_TOOLBAR_VIEW(toolbar_view), vbox); |
| 163 |
202 |
| |
203 GtkWidget *headerbar_sidebar = NULL; |
| |
204 GtkWidget *headerbar_main = adw_header_bar_new(); |
| |
205 GtkWidget *headerbar_right = NULL; |
| |
206 |
| |
207 GtkWidget *content = toolbar_view; |
| |
208 if(splitview) { |
| |
209 content = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL); |
| |
210 |
| |
211 GtkWidget *right_panel = adw_toolbar_view_new(); |
| |
212 GtkWidget *right_vbox = ui_gtk_vbox_new(0); |
| |
213 adw_toolbar_view_set_content(ADW_TOOLBAR_VIEW(right_panel), right_vbox); |
| |
214 |
| |
215 headerbar_right = adw_header_bar_new(); |
| |
216 adw_header_bar_set_show_title(ADW_HEADER_BAR(headerbar_right), FALSE); |
| |
217 adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(right_panel), headerbar_right); |
| |
218 |
| |
219 adw_header_bar_set_show_end_title_buttons(ADW_HEADER_BAR(headerbar_main), FALSE); |
| |
220 |
| |
221 gtk_paned_set_start_child(GTK_PANED(content), toolbar_view); |
| |
222 gtk_paned_set_end_child(GTK_PANED(content), right_panel); |
| |
223 |
| |
224 g_object_set_data(G_OBJECT(obj->widget), "ui_window_splitview", content); |
| |
225 g_object_set_data(G_OBJECT(obj->widget), "ui_left_panel", vbox); |
| |
226 g_object_set_data(G_OBJECT(obj->widget), "ui_right_panel", right_vbox); |
| |
227 } |
| |
228 |
| 164 GtkWidget *content_box = ui_gtk_vbox_new(0); |
229 GtkWidget *content_box = ui_gtk_vbox_new(0); |
| 165 BOX_ADD_EXPAND(GTK_BOX(vbox), content_box); |
230 BOX_ADD_EXPAND(GTK_BOX(vbox), content_box); |
| 166 |
231 |
| 167 GtkWidget *sidebar_headerbar = NULL; |
|
| 168 if(sidebar) { |
232 if(sidebar) { |
| 169 GtkWidget *splitview = adw_overlay_split_view_new(); |
233 GtkWidget *splitview = adw_overlay_split_view_new(); |
| 170 adw_application_window_set_content(ADW_APPLICATION_WINDOW(obj->widget), splitview); |
234 adw_application_window_set_content(ADW_APPLICATION_WINDOW(obj->widget), splitview); |
| 171 |
235 |
| 172 GtkWidget *sidebar_toolbar_view = adw_toolbar_view_new(); |
236 GtkWidget *sidebar_toolbar_view = adw_toolbar_view_new(); |
| 173 adw_overlay_split_view_set_sidebar(ADW_OVERLAY_SPLIT_VIEW(splitview), sidebar_toolbar_view); |
237 adw_overlay_split_view_set_sidebar(ADW_OVERLAY_SPLIT_VIEW(splitview), sidebar_toolbar_view); |
| 174 sidebar_headerbar = adw_header_bar_new(); |
238 headerbar_sidebar = adw_header_bar_new(); |
| 175 adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(sidebar_toolbar_view), sidebar_headerbar); |
239 adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(sidebar_toolbar_view), headerbar_sidebar); |
| 176 |
240 |
| 177 adw_overlay_split_view_set_content(ADW_OVERLAY_SPLIT_VIEW(splitview), toolbar_view); |
241 adw_overlay_split_view_set_content(ADW_OVERLAY_SPLIT_VIEW(splitview), content); |
| 178 |
242 |
| 179 g_object_set_data(G_OBJECT(obj->widget), "ui_sidebar", sidebar_toolbar_view); |
243 g_object_set_data(G_OBJECT(obj->widget), "ui_sidebar", sidebar_toolbar_view); |
| 180 } else { |
244 } else { |
| 181 adw_application_window_set_content(ADW_APPLICATION_WINDOW(obj->widget), toolbar_view); |
245 adw_application_window_set_content(ADW_APPLICATION_WINDOW(obj->widget), content); |
| 182 } |
246 } |
| 183 |
|
| 184 GtkWidget *headerbar = adw_header_bar_new(); |
|
| 185 |
247 |
| 186 const char *show_title = ui_get_property("ui.gtk.window.showtitle"); |
248 const char *show_title = ui_get_property("ui.gtk.window.showtitle"); |
| 187 if(show_title) { |
249 if(show_title) { |
| 188 if(!strcmp(show_title, "main") && sidebar) { |
250 if(!strcmp(show_title, "main") && sidebar) { |
| 189 adw_header_bar_set_show_title(ADW_HEADER_BAR(sidebar_headerbar), FALSE); |
251 adw_header_bar_set_show_title(ADW_HEADER_BAR(headerbar_sidebar), FALSE); |
| 190 } else if(!strcmp(show_title, "sidebar")) { |
252 } else if(!strcmp(show_title, "sidebar")) { |
| 191 adw_header_bar_set_show_title(ADW_HEADER_BAR(headerbar), FALSE); |
253 adw_header_bar_set_show_title(ADW_HEADER_BAR(headerbar_main), FALSE); |
| 192 } else if(!strcmp(show_title, "false")) { |
254 } else if(!strcmp(show_title, "false")) { |
| 193 adw_header_bar_set_show_title(ADW_HEADER_BAR(sidebar_headerbar), FALSE); |
255 adw_header_bar_set_show_title(ADW_HEADER_BAR(headerbar_sidebar), FALSE); |
| 194 adw_header_bar_set_show_title(ADW_HEADER_BAR(headerbar), FALSE); |
256 adw_header_bar_set_show_title(ADW_HEADER_BAR(headerbar_main), FALSE); |
| 195 } else { |
257 } else { |
| 196 fprintf(stderr, "Unknown value '%s' for property ui.gtk.window.showtitle\n", show_title); |
258 fprintf(stderr, "Unknown value '%s' for property ui.gtk.window.showtitle\n", show_title); |
| 197 adw_header_bar_set_show_title(ADW_HEADER_BAR(sidebar_headerbar), FALSE); |
259 adw_header_bar_set_show_title(ADW_HEADER_BAR(headerbar_sidebar), FALSE); |
| 198 } |
260 } |
| 199 } else { |
261 } else { |
| 200 adw_header_bar_set_show_title(ADW_HEADER_BAR(headerbar), FALSE); |
262 adw_header_bar_set_show_title(ADW_HEADER_BAR(headerbar_main), FALSE); |
| 201 } |
263 } |
| 202 |
264 |
| 203 adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(toolbar_view), headerbar); |
265 adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(toolbar_view), headerbar_main); |
| 204 g_object_set_data(G_OBJECT(obj->widget), "ui_headerbar", headerbar); |
266 g_object_set_data(G_OBJECT(obj->widget), "ui_headerbar", headerbar_main); |
| 205 |
267 |
| 206 if(!simple) { |
268 if(!simple) { |
| 207 ui_fill_headerbar(obj, headerbar); |
269 ui_fill_headerbar(obj, headerbar_main); |
| 208 } |
270 } |
| 209 #elif GTK_MAJOR_VERSION >= 4 |
271 #elif GTK_MAJOR_VERSION >= 4 |
| 210 GtkWidget *content_box = ui_gtk_vbox_new(0); |
272 GtkWidget *content_box = ui_gtk_vbox_new(0); |
| 211 WINDOW_SET_CONTENT(obj->widget, vbox); |
273 WINDOW_SET_CONTENT(obj->widget, vbox); |
| 212 if(!simple) { |
274 if(!simple) { |
| 284 return obj; |
346 return obj; |
| 285 } |
347 } |
| 286 |
348 |
| 287 |
349 |
| 288 UiObject* ui_window(const char *title, void *window_data) { |
350 UiObject* ui_window(const char *title, void *window_data) { |
| 289 return create_window(title, window_data, FALSE, FALSE); |
351 return create_window(title, window_data, FALSE, FALSE, FALSE); |
| 290 } |
352 } |
| 291 |
353 |
| 292 UiObject *ui_sidebar_window(const char *title, void *window_data) { |
354 UiObject *ui_sidebar_window(const char *title, void *window_data) { |
| 293 return create_window(title, window_data, TRUE, FALSE); |
355 return create_window(title, window_data, TRUE, FALSE, FALSE); |
| |
356 } |
| |
357 |
| |
358 UIEXPORT UiObject *ui_splitview_window(const char *title, UiBool sidebar) { |
| |
359 return create_window(title, NULL, sidebar, TRUE, FALSE); |
| 294 } |
360 } |
| 295 |
361 |
| 296 UiObject* ui_simple_window(const char *title, void *window_data) { |
362 UiObject* ui_simple_window(const char *title, void *window_data) { |
| 297 return create_window(title, window_data, FALSE, TRUE); |
363 return create_window(title, window_data, FALSE, FALSE, TRUE); |
| 298 } |
364 } |
| 299 |
365 |
| 300 void ui_window_size(UiObject *obj, int width, int height) { |
366 void ui_window_size(UiObject *obj, int width, int height) { |
| 301 gtk_window_set_default_size( |
367 gtk_window_set_default_size( |
| 302 GTK_WINDOW(obj->widget), |
368 GTK_WINDOW(obj->widget), |
| 303 width, |
369 width, |
| 304 height); |
370 height); |
| |
371 } |
| |
372 |
| |
373 void ui_window_default_size(UiObject *obj, int width, int height) { |
| |
374 window_default_width = width; |
| |
375 window_default_height = height; |
| 305 } |
376 } |
| 306 |
377 |
| 307 #ifdef UI_LIBADWAITA |
378 #ifdef UI_LIBADWAITA |
| 308 |
379 |
| 309 static void dialog_response(AdwAlertDialog *self, gchar *response, UiEventData *data) { |
380 static void dialog_response(AdwAlertDialog *self, gchar *response, UiEventData *data) { |