]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/multimon.cpp
917821d285c7948e0c9ecc103a5df1f3fa3dfada
[xonotic/netradiant.git] / radiant / multimon.cpp
1 /*
2    Copyright (C) 2001-2006, William Joseph.
3    All Rights Reserved.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #include "multimon.h"
23
24 #include "debugging/debugging.h"
25
26 #include "gtkutil/window.h"
27 #include "preferences.h"
28
29
30 multimon_globals_t g_multimon_globals;
31
32 LatchedValue<bool> g_Multimon_enableSysMenuPopups(false, "Floating windows sysmenu icons");
33
34 void MultiMonitor_constructPreferences(PreferencesPage &page)
35 {
36     ui::CheckButton primary_monitor = page.appendCheckBox("Multi Monitor", "Start on Primary Monitor",
37                                                           g_multimon_globals.m_bStartOnPrimMon);
38     ui::CheckButton popup = page.appendCheckBox(
39             "", "Disable system menu on popup windows",
40             mkImportExportCallback(g_Multimon_enableSysMenuPopups)
41     );
42     Widget_connectToggleDependency(popup, primary_monitor);
43 }
44
45 #include "preferencesystem.h"
46 #include "stringio.h"
47
48 #include <gdk/gdk.h>
49
50 namespace {
51     GdkRectangle primaryMonitor;
52 }
53
54 void PositionWindowOnPrimaryScreen(WindowPosition &position)
55 {
56     if (position.w >= primaryMonitor.width - 12) {
57         position.w = primaryMonitor.width - 12;
58     }
59     if (position.h >= primaryMonitor.height - 24) {
60         position.h = primaryMonitor.height - 48;
61     }
62     if (position.x <= primaryMonitor.x || position.x + position.w >= (primaryMonitor.x + primaryMonitor.width) - 12) {
63         position.x = primaryMonitor.x + 6;
64     }
65     if (position.y <= primaryMonitor.y || position.y + position.h >= (primaryMonitor.y + primaryMonitor.height) - 48) {
66         position.y = primaryMonitor.y + 24;
67     }
68 }
69
70 void MultiMon_Construct()
71 {
72     // detect multiple monitors
73
74     GdkScreen *screen = gdk_display_get_default_screen(gdk_display_get_default());
75     gint m = gdk_screen_get_n_monitors(screen);
76     globalOutputStream() << "default screen has " << m << " monitors\n";
77     for (int j = 0; j != m; ++j) {
78         GdkRectangle geom;
79         gdk_screen_get_monitor_geometry(screen, j, &geom);
80         globalOutputStream() << "monitor " << j << " geometry: " << geom.x << ", " << geom.y << ", " << geom.width
81                              << ", " << geom.height << "\n";
82         if (j == 0) {
83             // I am making the assumption that monitor 0 is always the primary monitor on win32. Tested on WinXP with gtk+-2.4.
84             primaryMonitor = geom;
85         }
86     }
87
88     if (m > 1) {
89         g_multimon_globals.m_bStartOnPrimMon = true;
90     }
91
92     GlobalPreferenceSystem().registerPreference("StartOnPrimMon",
93                                                 make_property_string(g_multimon_globals.m_bStartOnPrimMon));
94     GlobalPreferenceSystem().registerPreference("NoSysMenuPopups",
95                                                 make_property_string(g_Multimon_enableSysMenuPopups.m_latched));
96
97     g_Multimon_enableSysMenuPopups.useLatched();
98
99     PreferencesDialog_addInterfacePreferences(makeCallbackF(MultiMonitor_constructPreferences));
100 }
101
102 void MultiMon_Destroy()
103 {
104 }