aboutsummaryrefslogtreecommitdiff
path: root/src/Slit.hh
blob: 9384ad6dd9c81890256360f0a4fc056097d60a5c (plain)
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
// Slit.hh for Fluxbox
// Copyright (c) 2002 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org)
//
// Slit.hh for Blackbox - an X11 Window manager
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes at 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 SLIT_HH
#define SLIT_HH

#include "SlitTheme.hh"
#include "LayerMenu.hh"
#include "Layer.hh"

#ifdef XINERAMA
#include "Xinerama.hh"
#endif // XINERAMA

#include "FbTk/Menu.hh"
#include "FbTk/FbWindow.hh"
#include "FbTk/Timer.hh"
#include "FbTk/Resource.hh"
#include "FbTk/LayerItem.hh"
#include "FbTk/Signal.hh"

#include <X11/Xutil.h>

#include <list>
#include <memory>

class SlitClient;
class BScreen;
class FbMenu;
class Strut;
class Layer;

/// Handles dock apps
class Slit: public FbTk::EventHandler, public LayerObject, private FbTk::SignalTracker
{
public:
    typedef std::list<SlitClient *> SlitClients;
    /**
       Placement on screen
    */
    enum Placement {
        // top and bottom placement
        TOPLEFT = 1, TOPCENTER, TOPRIGHT,
        BOTTOMLEFT, BOTTOMCENTER, BOTTOMRIGHT,
        // left and right placement
        LEFTBOTTOM, LEFTCENTER, LEFTTOP,
        RIGHTBOTTOM, RIGHTCENTER, RIGHTTOP
    };

    Slit(BScreen &screen, FbTk::Layer &layer);
    virtual ~Slit();

    void show() { frame.window.show(); m_visible = true; }
    void hide() { frame.window.hide(); m_visible = false; }
    void setPlacement(Placement place);
    void addClient(Window clientwin);
    void removeClient(Window clientwin, bool remap = true);
    void reconfigure();
    void reposition();
    void shutdown();
    /// save clients name in a file
    void saveClientList();
    /// move client one position up
    void clientUp(SlitClient*);
    /// move client one position down
    void clientDown(SlitClient*);
    /// cycle slit clients up one step
    void cycleClientsUp();
    /// cycle slit clients down one step
    void cycleClientsDown();
    /**
       @name eventhandlers
    */
    //@{
    void handleEvent(XEvent &event);
    void buttonPressEvent(XButtonEvent &event);
    void enterNotifyEvent(XCrossingEvent &event);
    void leaveNotifyEvent(XCrossingEvent &event);
    void configureRequestEvent(XConfigureRequestEvent &event);
    void exposeEvent(XExposeEvent &event);
    //@}

    void moveToLayer(int layernum);
    void toggleHidden();

    BScreen &screen() { return m_screen; }
    const BScreen &screen() const { return m_screen; }
    FbTk::ThemeProxy<SlitTheme> &theme() { return *m_slit_theme.get(); }
    const FbTk::ThemeProxy<SlitTheme> &theme() const { return *m_slit_theme.get(); }

    int layerNumber() const { return m_layeritem->getLayerNum(); }

    bool isHidden() const { return m_hidden; }
    bool acceptKdeDockapp() const { return *m_rc_kde_dockapp; }
    bool doAutoHide() const { return *m_rc_auto_hide; }
    Placement placement() const { return *m_rc_placement; }
    int getOnHead() const { return *m_rc_on_head; }
    void saveOnHead(int head);
    FbTk::Menu &menu() { return m_slitmenu; }

    const FbTk::FbWindow &window() const { return frame.window; }

    int x() const { return (m_hidden ? frame.x_hidden : frame.x); }
    int y() const { return (m_hidden ? frame.y_hidden : frame.y); }

    unsigned int width() const { return frame.width; }
    unsigned int height() const { return frame.height; }
    const SlitClients &clients() const { return m_client_list; }
    SlitClients &clients() { return m_client_list; }
private:
    /// Called when screen has changed
    void screenSizeChanged(BScreen &screen);

    void updateAlpha();
    void clearWindow();
    void setupMenu();

    void removeClient(SlitClient *client, bool remap, bool destroy);
    void updateClientmenu();
    void clearStrut();
    void updateStrut();

    // m_hidden is for autohide, m_visible is the FbWindow state
    bool m_hidden, m_visible;

    BScreen &m_screen;
    FbTk::Timer m_timer;

    std::auto_ptr<LayerMenu> m_layermenu;
    FbMenu m_clientlist_menu, m_slitmenu;
#ifdef XINERAMA
    XineramaHeadMenu<Slit> *m_xineramaheadmenu;
#endif // XINERAMA

    struct frame {
        frame(const FbTk::FbWindow &parent):
            window(parent, 0, 0, 10, 10,
                   SubstructureRedirectMask |  ButtonPressMask |
                   EnterWindowMask | LeaveWindowMask | ExposureMask,
                   true),  // override redirect
            x(0), y(0), x_hidden(0), y_hidden(0),
        width(10), height(10) {}
        Pixmap pixmap;
        FbTk::FbWindow window;

        int x, y, x_hidden, y_hidden;
        unsigned int width, height;
    } frame;

    // for KDE
    Atom m_kwm1_dockwindow, m_kwm2_dockwindow;

    std::auto_ptr<FbTk::LayerItem> m_layeritem;
    std::auto_ptr<SlitTheme> m_slit_theme;
    static unsigned int s_eventmask;
    Strut *m_strut;

    class SlitClientsRes: public FbTk::Resource_base, public SlitClients {
    public:
        SlitClientsRes(FbTk::ResourceManager_base &rm, const std::string &name)
            : FbTk::Resource_base(name, name), m_rm(rm) {
            m_rm.addResource(*this);
        }

        ~SlitClientsRes() {
            m_rm.removeResource(*this);
        }

        virtual void setDefaultValue() {}
        virtual void setFromString(const char *) { assert(0); }
        virtual std::string getString() const { assert(0); }
        virtual void setFromLua(lua::state &l);
        virtual void pushToLua(lua::state &l) const;

    private:
        FbTk::ResourceManager_base &m_rm;
    };

    SlitClientsRes m_client_list;
    FbTk::BoolResource m_rc_kde_dockapp, m_rc_auto_hide, m_rc_maximize_over;
    FbTk::Resource<Slit::Placement, FbTk::EnumTraits<Slit::Placement> > m_rc_placement;
    FbTk::IntResource m_rc_alpha, m_rc_on_head;
    FbTk::Resource<ResourceLayer::Type, FbTk::EnumTraits<ResourceLayer::Type> > m_rc_layernum;
};


#endif // SLIT_HH