all repos — openbox @ 0305cbdc3ae8525c74b2bb9b23884035549e3407

openbox fork - make it a bit more like ryudo

src/Toolbar.hh (raw)

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
// -*- mode: C++; indent-tabs-mode: nil; -*-
// Toolbar.hh for Blackbox - an X11 Window manager
// Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

#ifndef   __Toolbar_hh
#define   __Toolbar_hh

extern "C" {
#include <X11/Xlib.h>
}

#include "Screen.hh"
#include "Basemenu.hh"
#include "Timer.hh"

// forward declaration
class Toolbar;

class Toolbarmenu : public Basemenu {
private:
  class Placementmenu : public Basemenu {
  private:
    Placementmenu(const Placementmenu&);
    Placementmenu& operator=(const Placementmenu&);
    Toolbar *toolbar;

  protected:
    virtual void itemSelected(int button, unsigned int index);
    virtual void setValues(void);

  public:
    Placementmenu(Toolbarmenu *tm);
    virtual void reconfigure(void);
  };

  Toolbar *toolbar;
  Placementmenu *placementmenu;

  friend class Placementmenu;
  friend class Toolbar;

  Toolbarmenu(const Toolbarmenu&);
  Toolbarmenu& operator=(const Toolbarmenu&);

protected:
  virtual void itemSelected(int button, unsigned int index);
  virtual void internal_hide(void);
  virtual void setValues(void);

public:
  Toolbarmenu(Toolbar *tb);
  ~Toolbarmenu(void);

  inline Basemenu *getPlacementmenu(void) { return placementmenu; }

  virtual void reconfigure(void);
};


class Toolbar : public TimeoutHandler {
private:
  bool on_top, editing, hidden, do_auto_hide;
  unsigned int width_percent;
  int placement;
  std::string toolbarstr;
  Display *display;

  struct ToolbarFrame {
    unsigned long button_pixel, pbutton_pixel;
    Pixmap base, label, wlabel, clk, button, pbutton;
    Window window, workspace_label, window_label, clock, psbutton, nsbutton,
      pwbutton, nwbutton;

    int x_hidden, y_hidden, hour, minute, grab_x, grab_y;
    unsigned int window_label_w, workspace_label_w, clock_w,
      button_w, bevel_w, label_h;

    Rect rect;
  } frame;

  class HideHandler : public TimeoutHandler {
  public:
    Toolbar *toolbar;

    virtual void timeout(void);
  } hide_handler;

  Blackbox *blackbox;
  BScreen *screen;
  Configuration *config;
  BTimer *clock_timer, *hide_timer;
  Toolbarmenu *toolbarmenu;
  Strut strut;

  std::string new_workspace_name;
  size_t new_name_pos;

  friend class HideHandler;
  friend class Toolbarmenu;
  friend class Toolbarmenu::Placementmenu;

  void redrawPrevWorkspaceButton(bool pressed = False, bool redraw = False);
  void redrawNextWorkspaceButton(bool pressed = False, bool redraw = False);
  void redrawPrevWindowButton(bool preseed = False, bool redraw = False);
  void redrawNextWindowButton(bool preseed = False, bool redraw = False);

  void updateStrut(void);

#ifdef    HAVE_STRFTIME
  void checkClock(bool redraw = False);
#else //  HAVE_STRFTIME
  void checkClock(bool redraw = False, bool date = False);
#endif // HAVE_STRFTIME

  Toolbar(const Toolbar&);
  Toolbar& operator=(const Toolbar&);

public:
  Toolbar(BScreen *scrn);
  virtual ~Toolbar(void);

  inline Toolbarmenu *getMenu(void) { return toolbarmenu; }

  inline bool isEditing(void) const { return editing; }
  inline bool isOnTop(void) const { return on_top; }
  inline bool isHidden(void) const { return hidden; }
  inline bool doAutoHide(void) const { return do_auto_hide; }
  inline unsigned int getWidthPercent(void) const { return width_percent; }
  inline int getPlacement(void) const { return placement; }
 
  void saveOnTop(bool);
  void saveAutoHide(bool);
  void saveWidthPercent(unsigned int);
  void savePlacement(int);

  void save_rc(void);
  void load_rc(void);

  inline Window getWindowID(void) const { return frame.window; }

  inline const Rect& getRect(void) const { return frame.rect; }
  inline unsigned int getWidth(void) const { return frame.rect.width(); }
  inline unsigned int getHeight(void) const { return frame.rect.height(); }
  inline unsigned int getExposedHeight(void) const
  { return ((do_auto_hide) ? frame.bevel_w : frame.rect.height()); }
  inline int getX(void) const
  { return ((hidden) ? frame.x_hidden : frame.rect.x()); }
  inline int getY(void) const
  { return ((hidden) ? frame.y_hidden : frame.rect.y()); }

  void buttonPressEvent(XButtonEvent *be);
  void buttonReleaseEvent(XButtonEvent *re);
  void enterNotifyEvent(XCrossingEvent * /*unused*/);
  void leaveNotifyEvent(XCrossingEvent * /*unused*/);
  void exposeEvent(XExposeEvent *ee);
  void keyPressEvent(XKeyEvent *ke);

  void edit(void);
  void reconfigure(void);
  void toggleAutoHide(void);

  void redrawWindowLabel(bool redraw = False);
  void redrawWorkspaceLabel(bool redraw = False);

  virtual void timeout(void);

  enum { TopLeft = 1, BottomLeft, TopCenter,
         BottomCenter, TopRight, BottomRight };
};


#endif // __Toolbar_hh