-
Notifications
You must be signed in to change notification settings - Fork 9
/
YGUI.cc
767 lines (658 loc) · 20.5 KB
/
YGUI.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
/********************************************************************
* YaST2-GTK - http://en.opensuse.org/YaST2-GTK *
********************************************************************/
/*
Textdomain "gtk"
*/
#include <string.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <YEvent.h>
#include <YMacro.h>
#include <YCommandLine.h>
#include "YGUI.h"
#include "YGi18n.h"
#include "YGUtils.h"
#include "YGDialog.h"
#include <glib.h>
#include <boost/filesystem.hpp>
static std::string askForFileOrDirectory (GtkFileChooserAction action,
const std::string &path, const std::string &filter, const std::string &title);
static void errorMsg (const char *msg)
{
GtkWidget* dialog = gtk_message_dialog_new (NULL,
GtkDialogFlags (0), GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", _("Error"));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", msg);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
#define DEFAULT_MACRO_FILE_NAME "macro.ycp"
#define BUSY_CURSOR_TIMEOUT 250
YUI *createUI( bool withThreads )
{
static YGUI *ui = 0;
if (!ui)
ui = new YGUI (withThreads);
return ui;
}
YGUI::YGUI (bool with_threads)
: YUI (with_threads), m_done_init (false), busy_timeout (0)
{
yuiMilestone() << "This is libyui-gtk " << VERSION << std::endl;
m_no_border = m_fullscreen = m_swsingle = false;
YGUI::setTextdomain( TEXTDOMAIN );
// If we're running without threads, initialize Gtk stuff
// This enables standalone libyui use Gtk interface
if (!with_threads)
checkInit();
// without this none of the (default) threading action works ...
topmostConstructorHasFinished();
}
void YGUI::setTextdomain( const char * domain )
{
bindtextdomain( domain, YSettings::localeDir().c_str() );
bind_textdomain_codeset( domain, "utf8" );
textdomain( domain );
// Make change known.
{
extern int _nl_msg_cat_cntr;
++_nl_msg_cat_cntr;
}
}
static void print_log (const gchar *domain, GLogLevelFlags level, const gchar *message, void *pData)
{
YUILogLevel_t ylevel = YUI_LOG_MILESTONE;
switch (level) {
case G_LOG_LEVEL_ERROR:
case G_LOG_LEVEL_CRITICAL:
ylevel = YUI_LOG_ERROR;
break;
case G_LOG_LEVEL_WARNING:
ylevel = YUI_LOG_WARNING;
break;
case G_LOG_LEVEL_DEBUG:
ylevel = YUI_LOG_DEBUG;
break;
case G_LOG_LEVEL_MESSAGE:
case G_LOG_LEVEL_INFO:
default:
break;
}
// YUILog.cc assumes 'logComponent' (etc.) are static strings, that it
// can just keep lying around for ever, and use later, so we have to
// intern the domain - that can be allocated (or belong to a transient
// plugin's address space).
const char *component = domain ? g_intern_string (domain) : "libyui-gtk";
YUILog::instance()->log (ylevel, component, "libyui-gtk", 0, "") << message << std::endl;
#if 0 // uncomment to put a stop to gdb
static int bugStop = 0;
if (bugStop-- <= 0)
abort();
#endif
}
void YGUI::checkInit()
{
if (m_done_init)
return;
// retrieve command line args from /proc/<pid>/cmdline
YCommandLine cmdLine;
int argc = cmdLine.argc();
char **argv = cmdLine.argv();
for (int i = 1; i < argc; i++) {
const char *argp = argv[i];
if (argp[0] != '-') {
if (!strcmp (argp, "sw_single") || !strcmp (argp, "online_update"))
m_swsingle = true;
continue;
}
argp++;
if (argp[0] == '-') argp++;
if (!strcmp (argp, "fullscreen"))
m_fullscreen = true;
else if (!strcmp (argp, "noborder"))
m_no_border = true;
else if (!strcmp (argp, "help")) {
printf ("%s",
_("Command line options for the YaST2 UI (GTK plugin):\n\n"
"--noborder no window manager border for main dialogs\n"
"--fullscreen use full screen for main dialogs\n"
"--nothreads run without additional UI threads\n"
"--help prints this help text\n"
"\n"
));
exit (0);
}
}
gtk_init (&argc, &argv);
g_log_set_default_handler (print_log, NULL); // send gtk logs to libyui system
#if 0 // to crash right away in order to get a stack trace
g_log_set_always_fatal (GLogLevelFlags (G_LOG_LEVEL_ERROR|G_LOG_LEVEL_CRITICAL|
G_LOG_LEVEL_WARNING| G_LOG_LEVEL_MESSAGE|G_LOG_LEVEL_INFO|G_LOG_LEVEL_DEBUG));
#endif
std::string themeSubDir = YSettings::themeDir();
char* st = getenv("Y2STYLE");
std::string style = st ? st : "";
if (style.size())
{
style = themeSubDir + style;
}
else
{
style = themeSubDir + "style.css";
}
yuiMilestone() << "Style \"" << style << "\"\n";
GtkCssProvider *provider = gtk_css_provider_new();
GFile * file = g_file_new_for_path(style.c_str());
if (g_file_query_exists(file, NULL))
{
GError *error = NULL;
if (!gtk_css_provider_load_from_file (provider, file, &error))
{
g_printerr ("%s\n", error->message);
}
else
{
GdkDisplay *display = gdk_display_get_default ();
GdkScreen *screen = gdk_display_get_default_screen (display);
gtk_style_context_add_provider_for_screen (screen,
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
}
else
yuiMilestone() << "Style \"" << style << "\" not found. Ignoring style\n";
g_object_unref (provider);
m_done_init = true;
}
GtkWidget* YGUI::loadIcon( const std::string & iconName ) const
{
// if extension is present we consider a full path name, theme icons don't have extensions
GtkWidget *icon = NULL;
if (boost::filesystem::path(iconName).has_extension())
{
icon = gtk_image_new_from_file(iconName.c_str());
}
else
{
GtkIconTheme * theme = gtk_icon_theme_get_default();
std::string ico = boost::filesystem::path(iconName).stem().c_str();
if (gtk_icon_theme_has_icon (theme, ico.c_str()))
{
icon = gtk_image_new_from_icon_name (ico.c_str(), GTK_ICON_SIZE_MENU);
}
else
{
// last chance, just to add an icon
icon = gtk_image_new_from_file(iconName.c_str());
}
}
return icon;
}
static gboolean ycp_wakeup_fn (GIOChannel *source, GIOCondition condition,
gpointer data)
{
*(int *)data = TRUE;
return TRUE;
}
void YGUI::idleLoop (int fd_ycp)
{
// The rational for this is that we need somewhere to run
// the magic 'main' thread, that can process thread unsafe
// incoming CORBA messages for us
checkInit();
GIOChannel *wakeup;
wakeup = g_io_channel_unix_new (fd_ycp);
g_io_channel_set_encoding (wakeup, NULL, NULL);
g_io_channel_set_buffered (wakeup, FALSE);
int woken = FALSE;
guint watch_tag = g_io_add_watch (wakeup, (GIOCondition)(G_IO_IN | G_IO_PRI),
ycp_wakeup_fn, &woken);
while (!woken)
g_main_context_iteration (NULL, TRUE);
g_source_remove (watch_tag);
g_io_channel_unref (wakeup);
}
static gboolean user_input_timeout_cb (YGUI *pThis)
{
if (!pThis->pendingEvent())
pThis->sendEvent (new YTimeoutEvent());
return FALSE;
}
// utility that implements both userInput() and pollInput()
YEvent *YGUI::waitInput (unsigned long timeout_ms, bool block)
{
checkInit();
if (!YDialog::currentDialog (false))
return NULL;
if (block)
normalCursor(); // waiting for input, so no more busy
guint timeout = 0;
if (timeout_ms > 0)
// timeout is automatically removed if callback returns FALSE
timeout = g_timeout_add (timeout_ms,
(GSourceFunc) user_input_timeout_cb, this);
if (block) {
while (!pendingEvent())
g_main_context_iteration (NULL, TRUE);
}
else
while (g_main_context_iteration (NULL, FALSE)) ;
YEvent *event = NULL;
if (pendingEvent())
event = m_event_handler.consumePendingEvent();
if (block) { // if YCP keeps working for more than X time, set busy cursor
if (busy_timeout)
g_source_remove (busy_timeout);
busy_timeout = g_timeout_add (BUSY_CURSOR_TIMEOUT, busy_timeout_cb, this);
}
return event;
}
void YGUI::sendEvent (YEvent *event)
{
m_event_handler.sendEvent (event);
g_main_context_wakeup (NULL);
}
gboolean YGUI::busy_timeout_cb (gpointer data)
{
YGUI *pThis = (YGUI *) data;
pThis->busyCursor();
pThis->busy_timeout = 0;
return FALSE;
}
void YGUI::busyCursor()
{
YGDialog *dialog = YGDialog::currentDialog();
if (dialog)
dialog->busyCursor();
}
void YGUI::normalCursor()
{
if (busy_timeout) {
g_source_remove (busy_timeout);
busy_timeout = 0;
}
YGDialog *dialog = YGDialog::currentDialog();
if (dialog)
dialog->normalCursor();
}
void YGUI::makeScreenShot()
{ ((YGApplication *) app())->makeScreenShot (""); }
YEvent *YGUI::runPkgSelection (YWidget *packageSelector)
{
yuiMilestone() << "Running package selection...\n";
YEvent *event = 0;
try {
event = packageSelector->findDialog()->waitForEvent();
} catch (const std::exception &e) {
yuiError() << "UI::RunPkgSelection() error: " << e.what() << std::endl;
yuiError() << "This is a libzypp problem. Do not file a bug against the UI!\n";
} catch (...) {
yuiError() << "UI::RunPkgSelection() error (unspecified)\n";
yuiError() << "This is a libzypp problem. Do not file a bug against the UI!\n";
}
return event;
}
void YGUI::askPlayMacro()
{
std::string filename = askForFileOrDirectory (GTK_FILE_CHOOSER_ACTION_OPEN,
DEFAULT_MACRO_FILE_NAME, "*.ycp", _("Open Macro file"));
if (!filename.empty()) {
busyCursor();
YMacro::play (filename);
sendEvent (new YEvent()); // flush
}
}
void YGUI::toggleRecordMacro()
{
if (YMacro::recording()) {
YMacro::endRecording();
normalCursor();
GtkWidget* dialog = gtk_message_dialog_new (NULL,
GtkDialogFlags (0), GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s",
_("Macro recording done."));
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
else {
std::string filename = askForFileOrDirectory (GTK_FILE_CHOOSER_ACTION_SAVE,
DEFAULT_MACRO_FILE_NAME, "*.ycp", _("Save Macro"));
if (!filename.empty())
YMacro::record (filename);
}
}
void YGUI::askSaveLogs()
{
std::string filename = askForFileOrDirectory (GTK_FILE_CHOOSER_ACTION_SAVE,
"/tmp/y2logs.tgz", "*.tgz *.tar.gz", _("Save y2logs"));
if (!filename.empty()) {
std::string command = "/usr/sbin/save_y2logs";
command += " '" + filename + "'";
yuiMilestone() << "Saving y2logs: " << command << std::endl;
int ret = system (command.c_str());
if (ret == 0)
yuiMilestone() << "y2logs saved to " << filename << std::endl;
else {
char *error = g_strdup_printf (
_("Could not run: '%s' (exit value: %d)"),
command.c_str(), ret);
yuiError() << error << std::endl;
errorMsg (error);
g_free (error);
}
}
}
//** YGApplication
YGApplication::YGApplication()
{
}
void YGApplication::makeScreenShot (const std::string &_filename)
{
std::string filename (_filename);
bool interactive = filename.empty();
GtkWidget *widget = GTK_WIDGET (YGDialog::currentWindow());
if (!widget) {
if (interactive)
errorMsg (_("No dialog to take screenshot of."));
return;
}
GtkAllocation alloc;
gtk_widget_get_allocation(widget, &alloc);
GError *error = 0;
GdkPixbuf *shot =
gdk_pixbuf_get_from_window (gtk_widget_get_window(widget),
0, 0, alloc.width,
alloc.height);
if (!shot) {
if (interactive)
errorMsg (_("Could not take screenshot."));
return;
}
if (interactive) {
//** ask user for filename
// calculate a default directory...
if (screenShotNameTemplate.empty()) {
std::string dir;
const char *homedir = getenv("HOME");
const char *ssdir = getenv("Y2SCREENSHOTS");
if (!homedir || !strcmp (homedir, "/")) {
// no homedir defined (installer)
dir = "/tmp/" + (ssdir ? (std::string(ssdir)) : (std::string("")));
if (mkdir (dir.c_str(), 0700) == -1)
dir = "";
}
else {
dir = homedir + (ssdir ? ("/" + std::string(ssdir)) : (std::string("")));
mkdir (dir.c_str(), 0750); // create a dir for what to put the pics
}
screenShotNameTemplate = dir + "/%s-%03d.png";
}
// calculate a default filename...
const char *baseName = "yast2-";
int nb;
std::map <std::string, int>::iterator it = screenShotNb.find (baseName);
if (it == screenShotNb.end())
nb = 0;
{
char *tmp_name = g_strdup_printf (screenShotNameTemplate.c_str(), baseName, nb);
filename = tmp_name;
g_free (tmp_name);
}
yuiDebug() << "screenshot: " << filename << std::endl;
filename = askForFileOrDirectory (
GTK_FILE_CHOOSER_ACTION_SAVE, "", "*.png", _("Save screenshot"));
if (filename.empty()) { // user dismissed the dialog
yuiDebug() << "Save screen shot canceled by user\n";
goto makeScreenShot_ret;
}
screenShotNb.erase (baseName);
screenShotNb[baseName] = nb + 1;
}
yuiDebug() << "Saving screen shot to " << filename << std::endl;
if (!gdk_pixbuf_save (shot, filename.c_str(), "png", &error, NULL)) {
std::string msg = _("Could not save to:");
msg += " "; msg += filename;
if (error) {
msg += "\n"; msg += "\n";
msg += error->message;
}
yuiError() << msg << std::endl;
if (interactive)
errorMsg (msg.c_str());
goto makeScreenShot_ret;
}
makeScreenShot_ret:
g_object_unref (G_OBJECT (shot));
}
void YGApplication::beep()
{
GtkWindow *window = YGDialog::currentWindow();
if (window) {
gtk_window_present (window);
gtk_widget_error_bell (GTK_WIDGET (window));
}
else
gdk_beep();
}
// File/directory dialogs
#include <sstream>
std::string askForFileOrDirectory (GtkFileChooserAction action,
const std::string &path, const std::string &filter, const std::string &title)
{
GtkWindow *parent = YGDialog::currentWindow();
const char *button;
switch (action) {
case GTK_FILE_CHOOSER_ACTION_SAVE:
button = _("_Save"); break;
case GTK_FILE_CHOOSER_ACTION_OPEN:
button = _("_Open"); break;
case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER:
case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
default:
button = _("Select"); break;
}
GtkWidget *dialog;
dialog = gtk_file_chooser_dialog_new (title.c_str(),
parent, action, _("_Cancel"), GTK_RESPONSE_CANCEL,
button, GTK_RESPONSE_ACCEPT, NULL);
GtkFileChooser *fileChooser = GTK_FILE_CHOOSER (dialog);
gtk_file_chooser_set_local_only (fileChooser, TRUE);
gtk_file_chooser_set_do_overwrite_confirmation (fileChooser, TRUE);
// filepath can be a dir or a file path, split that up
std::string dirname, filename;
if (!path.empty()) {
if (path[0] != '/')
yuiWarning() << "FileDialog: Relative paths are not supported: '" << path << "'\n";
else if (!g_file_test (path.c_str(), G_FILE_TEST_EXISTS))
yuiWarning() << "FileDialog: Path doesn't exist: '" << path << "'\n";
else if (g_file_test (path.c_str(), G_FILE_TEST_IS_DIR))
dirname = path;
else { // its a file
std::string::size_type i = path.find_last_of ("/");
if (i != std::string::npos) {
dirname = path.substr (0, i+1);
filename = path.substr (i+1);
}
}
}
if (!dirname.empty())
gtk_file_chooser_set_current_folder (fileChooser, dirname.c_str());
if (!filename.empty())
gtk_file_chooser_set_current_name (fileChooser, filename.c_str());
if (!filter.empty() && filter != "*") {
GtkFileFilter *gtk_filter = gtk_file_filter_new();
gtk_file_filter_set_name (gtk_filter, filter.c_str());
// cut filter_pattern into chuncks like GTK likes
std::istringstream stream (filter);
while (!stream.eof()) {
std::string str;
stream >> str;
if (!str.empty() && str [str.size()-1] == ',')
str.erase (str.size()-1);
gtk_file_filter_add_pattern (gtk_filter, str.c_str());
}
gtk_file_chooser_add_filter (fileChooser, gtk_filter);
}
// bug 335492: because "/" gets hidden as a an arrow at the top, make sure
// there is a root shortcut at the side pane (will not add if already exists)
gtk_file_chooser_add_shortcut_folder (fileChooser, "/", NULL);
std::string ret;
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
gchar *filename = gtk_file_chooser_get_filename (fileChooser);
if (filename) {
ret = filename;
g_free (filename);
}
}
gtk_widget_destroy (dialog);
return ret;
}
std::string YGApplication::askForExistingDirectory (
const std::string &path, const std::string &title)
{ return askForFileOrDirectory (GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, path, "", title); }
std::string YGApplication::askForExistingFile (
const std::string &path, const std::string &filter, const std::string &title)
{ return askForFileOrDirectory (GTK_FILE_CHOOSER_ACTION_OPEN, path, filter, title); }
std::string YGApplication::askForSaveFileName (
const std::string &path, const std::string &filter, const std::string &title)
{ return askForFileOrDirectory (GTK_FILE_CHOOSER_ACTION_SAVE, path, filter, title); }
std::string YGApplication::glyph (const std::string &sym)
{
bool reverse = gtk_widget_get_default_direction() == GTK_TEXT_DIR_RTL;
if (sym == YUIGlyph_ArrowLeft)
return reverse ? "\u25b6" : "\u25c0";
if (sym == YUIGlyph_ArrowRight)
return reverse ? "\u25c0" : "\u25b6";
if (sym == YUIGlyph_ArrowUp)
return "\u25b2";
if (sym == YUIGlyph_ArrowDown)
return "\u25bc";
if (sym == YUIGlyph_CheckMark)
return "\u2714";
if (sym == YUIGlyph_BulletArrowRight)
return reverse ? "\u21e6" : "\u279c";
if (sym == YUIGlyph_BulletCircle)
return "\u26ab";
if (sym == YUIGlyph_BulletSquare)
return "\u25fe";
return "";
}
// YWidget layout units -> pixels conversion. Same as yast-qt's.
int YGApplication::deviceUnits (YUIDimension dim, float size)
{
if (dim == YD_HORIZ)
size *= 640.0 / 80;
else
size *= 480.0 / 25;
return size + 0.5;
}
float YGApplication::layoutUnits (YUIDimension dim, int units)
{
float size = (float) units;
if (dim == YD_HORIZ) return size * (80/640.0);
else return size * (25/480.0);
}
static inline GdkScreen *getScreen ()
{ return gdk_display_get_default_screen (gdk_display_get_default()); }
// GTK doesn't seem to have some desktopWidth/Height like Qt, so we to report
// a reduced display size to compensate for the panel, or the window frame
//
// * For GTK3 get the GdkWindow out of the GtkWindow widget with gtk_widget_get_window(),
// and then use gdk_display_get_monitor_at_window()
//
// The idea was to use YGDialog::currentWindow() but it next function is used in the YGDialog
// constructor and the pointer is not reliable and sometimes crashes (To be investigated more)
// Example of code is the next:
// GdkMonitor * pMonitor = NULL;
// GtkWindow* pWindow = YGDialog::currentWindow();
// GtkWidget *widget = NULL;
// if (pWindow)
// {
// widget = GTK_WIDGET (pWindow);
// }
// if (widget) {
// pMonitor = gdk_display_get_monitor_at_window (
// gdk_display_get_default(),
// gtk_widget_get_window(widget)
// );
// }
static inline GdkMonitor * getGdkMonitor()
{
GdkMonitor * pMonitor = gdk_display_get_monitor_at_window (
gdk_display_get_default(),
gdk_get_default_root_window ()
);
return pMonitor;
}
int YGApplication::displayWidth()
{
GdkMonitor * pMonitor = getGdkMonitor();
if (pMonitor)
{
GdkRectangle geometry;
gdk_monitor_get_geometry (pMonitor, &geometry);
return geometry.width;
}
return 640;
}
int YGApplication::displayHeight()
{
GdkMonitor * pMonitor = getGdkMonitor();
if (pMonitor)
{
GdkRectangle geometry;
gdk_monitor_get_geometry (pMonitor, &geometry);
return geometry.height;
}
return 480;
}
int YGApplication::displayDepth()
{
# if GTK_CHECK_VERSION (3, 22, 0)
return gdk_visual_get_depth (gdk_screen_get_system_visual (
gdk_screen_get_default ()));
# else
return gdk_visual_get_best_depth();
#endif
}
long YGApplication::displayColors()
{ return 1L << displayDepth(); /*from yast-qt*/ }
// Get default size as in Qt as much as possible
int YGApplication::defaultWidth()
{
GdkMonitor * pMonitor = getGdkMonitor();
GdkRectangle availableSize = {0};
if (pMonitor)
{
gdk_monitor_get_workarea(pMonitor, &availableSize);
}
int width = availableSize.width;
if ( displayWidth() >= 1024 )
{
// Scale down to 70% of screen size
width = std::max( (int) (availableSize.width * 0.7), 1024 ) ;
}
return width;
}
int YGApplication::defaultHeight()
{
GdkMonitor * pMonitor = getGdkMonitor();
GdkRectangle availableSize = {0};
if (pMonitor)
{
gdk_monitor_get_workarea(pMonitor, &availableSize);
}
int height = availableSize.height;
if ( displayHeight() >= 768 )
{
// Scale down to 70% of screen size
height = std::max( (int) (availableSize.height * 0.7), 768 ) ;
}
return height;
}
YWidgetFactory *YGUI::createWidgetFactory()
{ return new YGWidgetFactory; }
YOptionalWidgetFactory *YGUI::createOptionalWidgetFactory()
{ return new YGOptionalWidgetFactory; }
YApplication *YGUI::createApplication()
{ return new YGApplication(); }