PieDock  1.6.3
Settings.h
1 /*
2  * O ,-
3  * ° o . -´ ' ,-
4  * ° .´ ` . ´,´
5  * ( ° )) . (
6  * `-;_ . -´ `.`.
7  * `._' ´
8  *
9  * Copyright (c) 2007-2012 Markus Fisch <mf@markusfisch.de>
10  *
11  * Licensed under the MIT license:
12  * http://www.opensource.org/licenses/mit-license.php
13  */
14 #ifndef _PieDock_Settings_
15 #define _PieDock_Settings_
16 
17 #include "MenuItems.h"
18 #include "IconMap.h"
19 #include "ActiveIndicator.h"
20 #include "Text.h"
21 #include "WorkspaceLayout.h"
22 
23 #include <X11/Xlib.h>
24 #include <vector>
25 #include <string>
26 #include <istream>
27 #include <stdexcept>
28 
29 namespace PieDock
30 {
36  class Settings
37  {
38  public:
39  enum Action
40  {
41  NoAction,
42  Launch,
43  ShowNext,
44  ShowPrevious,
45  ShowWindows,
46  Hide,
47  Close,
48  SpinUp,
49  SpinDown,
50  SpinNext,
51  SpinPrevious,
52  Disappear
53  };
54 
55  enum CenterAction
56  {
57  CenterIgnore,
58  CenterNearestIcon,
59  CenterDisappear
60  };
61 
62  typedef struct Trigger
63  {
64  unsigned int modifier;
65  union
66  {
67  unsigned int button;
68  KeySym keySym;
69  };
70  std::string menuName;
71  unsigned int eventMask;
72  } Key, Button;
73 
74  typedef struct
75  {
76  unsigned int button;
77  Action action;
79 
80  typedef struct
81  {
82  KeySym keySym;
83  Action action;
84  unsigned int eventType;
85  } KeyFunction;
86 
87  typedef struct
88  {
89  int cornerRadius;
90  int alpha;
91  unsigned int color;
93 
94  typedef struct
95  {
96  bool visible;
97  WorkspaceLayout::PreferredVirtualLayout preferredLayout;
98  unsigned int workspaceColor;
99  unsigned int windowColor;
101 
102  typedef std::vector<Key> Keys;
103  typedef std::vector<Button> Buttons;
104  typedef std::vector<ButtonFunction> ButtonFunctions;
105  typedef std::vector<KeyFunction> KeyFunctions;
106  typedef std::map<std::string, MenuItems> Menus;
107  typedef std::map<std::string, bool> WindowsToIgnore;
108 
109  Settings() {}
110  virtual ~Settings() { clearMenus(); }
111  inline const std::string &getConfigurationFile() const {
112  return configurationFile; }
113  inline void setConfigurationFile( std::string s ) {
114  configurationFile = s; }
115  inline const int &getWidth() const { return width; }
116  inline const int &getHeight() const { return height; }
117 #ifdef HAVE_XRENDER
118  inline const bool &useCompositing() const { return compositing; }
119 #endif
120  inline Keys &getKeys() { return keys; }
121  inline Buttons &getButtons() { return buttons; }
122  inline KeyFunctions &getKeyFunctions() {
123  return keyFunctions; }
124  inline IconMap &getIconMap() { return iconMap; }
125  inline MenuItems *getMenu( std::string s ) {
126  Menus::iterator i = menus.find( s );
127  if( i == menus.end() )
128  return 0;
129  return &(*i).second; }
130  inline bool ignoreWindow( std::string s ) {
131  return (windowsToIgnore.find( s ) != windowsToIgnore.end()); }
132  inline ActiveIndicator &getActiveIndicator() {
133  return activeIndicator; }
134  inline const int &getFocusedAlpha() const { return focusedAlpha; }
135  inline const int &getUnfocusedAlpha() const {
136  return unfocusedAlpha; }
137  inline const double &getStartRadius() const {
138  return startRadius; }
139  inline const bool &isFitts() const { return fitts; }
140  inline const double &getZoomModifier() const {
141  return zoomModifier; }
142  inline const CenterAction &getCenterAction() const {
143  return centerAction; }
144  inline const double &getSpinStep() const { return spinStep; }
145  inline const bool &getShowTitle() const { return showTitle; }
146  inline const Text::Font &getTitleFont() const { return titleFont; }
147  inline const CartoucheSettings &getCartoucheSettings() const {
148  return cartoucheSettings; }
149  inline const int &getMinimumNumber() const { return minimumNumber; }
150  inline const WorkspaceDisplaySettings
151  &getWorkspaceDisplaySettings() const {
152  return workspaceDisplaySettings; }
153  virtual void setConfigurationFileFromBinary( std::string );
154  virtual ButtonFunctions getButtonFunctions(
155  const std::string &menu = std::string(),
156  MenuItem *item = 0 );
157  virtual void load( Display *d );
158 
159  protected:
160  virtual int readMenu( std::istream &, int, std::string );
161  virtual void clearMenus();
162  virtual Action resolveActionString( const std::string & ) const;
163  virtual unsigned int resolveButtonCode( const std::string & ) const;
164  virtual void throwParsingError( const char *, unsigned int ) const;
165  virtual void presizeIcon( Icon *, int, int, int, int, int, int );
166 
167  private:
171  class Statement : public std::string
172  {
173  public:
174  Statement( const char *s ) : std::string( s ) {}
175  Statement( std::string s ) : std::string( s ) {}
176  Statement() : std::string() {}
177  virtual ~Statement() {}
178  void cutComments( const char = '#' );
179  std::vector<std::string> split( const char * = " \t" );
180 
181  private:
182  bool tokenize( const char *,
183  std::string::size_type &,
184  std::string::size_type & );
185  std::string trim( std::string,
186  const char * = " \t\r\n\"" );
187  };
188 
189  std::string configurationFile;
190  int width;
191  int height;
192  Keys keys;
193  Buttons buttons;
194  ButtonFunctions buttonFunctions;
195  std::map<MenuItem *, ButtonFunctions> itemButtonFunctions;
196  std::map<std::string, ButtonFunctions> menuButtonFunctions;
197  KeyFunctions keyFunctions;
198  IconMap iconMap;
199  Menus menus;
200  WindowsToIgnore windowsToIgnore;
201  ActiveIndicator activeIndicator;
202  int focusedAlpha;
203  int unfocusedAlpha;
204  double startRadius;
205  bool fitts;
206  double zoomModifier;
207  CenterAction centerAction;
208  double spinStep;
209  bool showTitle;
210  Text::Font titleFont;
211  CartoucheSettings cartoucheSettings;
212  int minimumNumber;
213  WorkspaceDisplaySettings workspaceDisplaySettings;
214 #ifdef HAVE_XRENDER
215  bool compositing;
216 #endif
217  };
218 }
219 
220 #endif