1 // Layer.hh for Fluxbox Window Manager
2 // Copyright (c) 2006 Fluxbox Team (fluxgen at fluxbox dot org)
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21 
22 #ifndef RESOURCE_LAYER_HH
23 #define RESOURCE_LAYER_HH
24 
25 #include "FbTk/StringUtil.hh"
26 
27 /**
28  * (This is not the layer->raise/lower handling stuff, @see FbTk::Layer)
29  * Class to store layer numbers (special Resource type)
30  * we have a special resource type because we need to be able to name certain layers
31  * a Resource<int> wouldn't allow this
32  */
33 class  ResourceLayer {
34 public:
35     enum {
36         MENU = 0,
37         ABOVE_DOCK = 2,
38         DOCK = 4,
39         TOP = 6,
40         NORMAL = 8,
41         BOTTOM = 10,
42         DESKTOP = 12,
43         NUM_LAYERS = 13
44     };
45 
ResourceLayer(int i)46     explicit ResourceLayer(int i) : m_num(i) {};
47 
getNumFromString(const std::string & str)48     static int getNumFromString(const std::string &str) {
49         int tempnum = 0;
50         std::string v = FbTk::StringUtil::toLower(str);
51         if (FbTk::StringUtil::extractNumber(str, tempnum))
52             return tempnum;
53         if (v == "menu")
54             return ::ResourceLayer::MENU;
55         if (v == "abovedock")
56             return ::ResourceLayer::ABOVE_DOCK;
57         if (v == "dock")
58             return ::ResourceLayer::DOCK;
59         if (v == "top")
60             return ::ResourceLayer::TOP;
61         if (v == "normal")
62             return ::ResourceLayer::NORMAL;
63         if (v == "bottom")
64             return ::ResourceLayer::BOTTOM;
65         if (v == "desktop")
66             return ::ResourceLayer::DESKTOP;
67         return -1;
68     }
69 
getString(int num)70     static std::string getString(int num) {
71         switch (num) {
72         case ::ResourceLayer::MENU:
73             return std::string("Menu");
74         case ::ResourceLayer::ABOVE_DOCK:
75             return std::string("AboveDock");
76         case ::ResourceLayer::DOCK:
77             return std::string("Dock");
78         case ::ResourceLayer::TOP:
79             return std::string("Top");
80         case ::ResourceLayer::NORMAL:
81             return std::string("Normal");
82         case ::ResourceLayer::BOTTOM:
83             return std::string("Bottom");
84         case ::ResourceLayer::DESKTOP:
85             return std::string("Desktop");
86         default:
87            return FbTk::StringUtil::number2String(num);
88         }
89     }
90 
getNum() const91     int getNum() const { return m_num; }
getString() const92     std::string getString() const { return getString(m_num); }
93 
operator =(int num)94     ResourceLayer &operator=(int num) { m_num = num; return *this; }
95 
96 private:
97     int m_num;
98 };
99 
100 #endif // RESOURCE_LAYER_HH
101