fbe000de9e66dad4fc10dd82a70b3cc083899886
1 /** \file
2 * Desktop widget implementation
3 */
4 /* Authors:
5 * Jon A. Cruz <jon@joncruz.org>
6 *
7 * Copyright (C) 2010 Jon A. Cruz
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
12 #ifdef HAVE_CONFIG_H
13 # include "config.h"
14 #endif
16 #include <algorithm>
18 #include "uxmanager.h"
19 #include "desktop.h"
20 #include "util/ege-tags.h"
21 #include "widgets/toolbox.h"
22 #include "widgets/desktop-widget.h"
23 #include "preferences.h"
24 #include "gdkmm/screen.h"
26 #ifdef GDK_WINDOWING_X11
27 #include <gdk/gdkx.h>
28 #endif // GDK_WINDOWING_X11
30 using std::map;
31 using std::vector;
34 gchar const* KDE_WINDOW_MANAGER_NAME = "KWin";
35 gchar const* UNKOWN_WINDOW_MANAGER_NAME = "unknown";
38 static vector<SPDesktop*> desktops;
39 static vector<SPDesktopWidget*> dtws;
40 static map<SPDesktop*, vector<GtkWidget*> > trackedBoxes;
43 namespace {
44 // TODO unify this later:
45 static Glib::ustring getLayoutPrefPath( Inkscape::UI::View::View *view )
46 {
47 Glib::ustring prefPath;
49 if (reinterpret_cast<SPDesktop*>(view)->is_focusMode()) {
50 prefPath = "/focus/";
51 } else if (reinterpret_cast<SPDesktop*>(view)->is_fullscreen()) {
52 prefPath = "/fullscreen/";
53 } else {
54 prefPath = "/window/";
55 }
57 return prefPath;
58 }
60 }
62 namespace Inkscape {
63 namespace UI {
65 UXManager* instance = 0;
67 class UXManagerImpl : public UXManager
68 {
69 public:
70 UXManagerImpl();
71 virtual ~UXManagerImpl();
73 virtual void addTrack( SPDesktopWidget* dtw );
74 virtual void delTrack( SPDesktopWidget* dtw );
76 virtual void connectToDesktop( vector<GtkWidget *> const & toolboxes, SPDesktop *desktop );
78 virtual gint getDefaultTask( SPDesktop *desktop );
79 virtual void setTask(SPDesktop* dt, gint val);
81 virtual bool isFloatWindowProblem() const;
82 virtual bool isWidescreen() const;
84 private:
85 bool _floatwindowIssues;
86 bool _widescreen;
87 };
89 UXManager* UXManager::getInstance()
90 {
91 if (!instance) {
92 instance = new UXManagerImpl();
93 }
94 return instance;
95 }
98 UXManager::UXManager()
99 {
100 }
102 UXManager::~UXManager()
103 {
104 }
106 UXManagerImpl::UXManagerImpl() :
107 _floatwindowIssues(false),
108 _widescreen(false)
109 {
110 ege::TagSet tags;
111 tags.setLang("en");
113 tags.addTag(ege::Tag("General"));
114 tags.addTag(ege::Tag("Icons"));
116 #if defined(GDK_WINDOWING_X11)
117 char const* wmName = gdk_x11_screen_get_window_manager_name( gdk_screen_get_default() );
118 //g_message("Window manager is [%s]", wmName);
120 //if (g_ascii_strcasecmp( wmName, UNKOWN_WINDOW_MANAGER_NAME ) == 0) {
121 if (g_ascii_strcasecmp( wmName, KDE_WINDOW_MANAGER_NAME ) == 0) {
122 _floatwindowIssues = true;
123 }
124 #elif defined(GDK_WINDOWING_WIN32)
125 _floatwindowIssues = true;
126 #endif // GDK_WINDOWING_WIN32
129 Glib::RefPtr<Gdk::Screen> defaultScreen = Gdk::Screen::get_default();
130 if (defaultScreen) {
131 int width = defaultScreen->get_width();
132 int height = defaultScreen->get_height();
133 gdouble aspect = static_cast<gdouble>(width) / static_cast<gdouble>(height);
134 if (aspect > 1.4) {
135 _widescreen = true;
136 }
137 }
138 }
140 UXManagerImpl::~UXManagerImpl()
141 {
142 }
144 bool UXManagerImpl::isFloatWindowProblem() const
145 {
146 return _floatwindowIssues;
147 }
149 bool UXManagerImpl::isWidescreen() const
150 {
151 return _widescreen;
152 }
154 gint UXManagerImpl::getDefaultTask( SPDesktop *desktop )
155 {
156 gint taskNum = isWidescreen() ? 2 : 0;
158 Glib::ustring prefPath = getLayoutPrefPath( desktop );
159 taskNum = Inkscape::Preferences::get()->getInt( prefPath + "task/taskset", taskNum );
160 taskNum = (taskNum < 0) ? 0 : (taskNum > 2) ? 2 : taskNum;
162 return taskNum;
163 }
165 void UXManagerImpl::setTask(SPDesktop* dt, gint val)
166 {
167 for (vector<SPDesktopWidget*>::iterator it = dtws.begin(); it != dtws.end(); ++it) {
168 SPDesktopWidget* dtw = *it;
170 gboolean notDone = Inkscape::Preferences::get()->getBool("/options/workarounds/dynamicnotdone", false);
172 if (dtw->desktop == dt) {
173 int taskNum = val;
174 switch (val) {
175 default:
176 case 0:
177 dtw->setToolboxPosition("ToolToolbar", GTK_POS_LEFT);
178 dtw->setToolboxPosition("CommandsToolbar", GTK_POS_TOP);
179 if (notDone) {
180 dtw->setToolboxPosition("AuxToolbar", GTK_POS_TOP);
181 }
182 dtw->setToolboxPosition("SnapToolbar", GTK_POS_RIGHT);
183 taskNum = val; // in case it was out of range
184 break;
185 case 1:
186 dtw->setToolboxPosition("ToolToolbar", GTK_POS_LEFT);
187 dtw->setToolboxPosition("CommandsToolbar", GTK_POS_TOP);
188 if (notDone) {
189 dtw->setToolboxPosition("AuxToolbar", GTK_POS_TOP);
190 }
191 dtw->setToolboxPosition("SnapToolbar", GTK_POS_TOP);
192 break;
193 case 2:
194 dtw->setToolboxPosition("ToolToolbar", GTK_POS_LEFT);
195 dtw->setToolboxPosition("CommandsToolbar", GTK_POS_RIGHT);
196 dtw->setToolboxPosition("SnapToolbar", GTK_POS_RIGHT);
197 if (notDone) {
198 dtw->setToolboxPosition("AuxToolbar", GTK_POS_RIGHT);
199 }
200 }
201 Glib::ustring prefPath = getLayoutPrefPath( dtw->desktop );
202 Inkscape::Preferences::get()->setInt( prefPath + "task/taskset", taskNum );
203 }
204 }
205 }
208 void UXManagerImpl::addTrack( SPDesktopWidget* dtw )
209 {
210 if (std::find(dtws.begin(), dtws.end(), dtw) == dtws.end()) {
211 dtws.push_back(dtw);
212 }
213 }
215 void UXManagerImpl::delTrack( SPDesktopWidget* dtw )
216 {
217 vector<SPDesktopWidget*>::iterator iter = std::find(dtws.begin(), dtws.end(), dtw);
218 if (iter != dtws.end()) {
219 dtws.erase(iter);
220 }
221 }
223 void UXManagerImpl::connectToDesktop( vector<GtkWidget *> const & toolboxes, SPDesktop *desktop )
224 {
225 //static map<SPDesktop*, vector<GtkWidget*> > trackedBoxes;
227 for (vector<GtkWidget*>::const_iterator it = toolboxes.begin(); it != toolboxes.end(); ++it ) {
228 GtkWidget* toolbox = *it;
230 ToolboxFactory::setToolboxDesktop( toolbox, desktop );
231 vector<GtkWidget*>& tracked = trackedBoxes[desktop];
232 if (find(tracked.begin(), tracked.end(), toolbox) == tracked.end()) {
233 tracked.push_back(toolbox);
234 }
235 }
237 if (std::find(desktops.begin(), desktops.end(), desktop) == desktops.end()) {
238 desktops.push_back(desktop);
239 }
241 gint taskNum = getDefaultTask( desktop );
243 // note: this will change once more options are in the task set support:
244 Inkscape::UI::UXManager::getInstance()->setTask( desktop, taskNum );
245 }
248 } // namespace UI
249 } // namespace Inkscape
251 /*
252 Local Variables:
253 mode:c++
254 c-file-style:"stroustrup"
255 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
256 indent-tabs-mode:nil
257 fill-column:99
258 End:
259 */
260 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :