kranewm

An ICCCM & EWMH compliant X11 reparenting, dynamic window manager, written in C++
git clone git://git.deurzen.net/kranewm
Log | Files | Refs | LICENSE

stack.cc (3526B)


      1 #include "stack.hh"
      2 #include "../winsys/util.hh"
      3 
      4 StackHandler::StackHandler()
      5     : m_layers({}),
      6       m_desktop({}),
      7       m_below({}),
      8       m_dock({}),
      9       m_above({}),
     10       m_notification({}),
     11       m_above_other({}),
     12       m_below_other({})
     13 {}
     14 
     15 StackHandler::~StackHandler()
     16 {}
     17 
     18 void
     19 StackHandler::add_window(winsys::Window window, StackLayer layer)
     20 {
     21     if (!(m_layers.count(window) > 0)) {
     22         std::vector<winsys::Window>* windows;
     23 
     24         switch (layer) {
     25         case StackLayer::Desktop:      windows = &m_desktop;      break;
     26         case StackLayer::Below_:       windows = &m_below;        break;
     27         case StackLayer::Dock:         windows = &m_dock;         break;
     28         case StackLayer::Above_:       windows = &m_above;        break;
     29         case StackLayer::Notification: windows = &m_notification; break;
     30         default: Util::die("no associated layer");
     31         }
     32 
     33         windows->push_back(window);
     34         m_layers[window] = layer;
     35     }
     36 }
     37 
     38 void
     39 StackHandler::remove_window(winsys::Window window)
     40 {
     41     if (m_layers.count(window) > 0) {
     42         StackLayer layer = m_layers.at(window);
     43         std::vector<winsys::Window>* windows;
     44 
     45         switch (layer) {
     46         case StackLayer::Desktop:      windows = &m_desktop;      break;
     47         case StackLayer::Below_:       windows = &m_below;        break;
     48         case StackLayer::Dock:         windows = &m_dock;         break;
     49         case StackLayer::Above_:       windows = &m_above;        break;
     50         case StackLayer::Notification: windows = &m_notification; break;
     51         default: Util::die("no associated layer");
     52         }
     53 
     54         Util::erase_remove(*windows, window);
     55         m_layers.erase(window);
     56     }
     57 
     58     m_above_other.erase(window);
     59     m_below_other.erase(window);
     60 }
     61 
     62 
     63 void
     64 StackHandler::relayer_window(winsys::Window window, StackLayer layer)
     65 {
     66     remove_window(window);
     67     add_window(window, layer);
     68 }
     69 
     70 void
     71 StackHandler::raise_window(winsys::Window window)
     72 {
     73     if (m_layers.count(window) > 0) {
     74         StackLayer layer = m_layers.at(window);
     75         std::vector<winsys::Window>* windows;
     76 
     77         switch (layer) {
     78         case StackLayer::Desktop:      windows = &m_desktop;      break;
     79         case StackLayer::Below_:       windows = &m_below;        break;
     80         case StackLayer::Dock:         windows = &m_dock;         break;
     81         case StackLayer::Above_:       windows = &m_above;        break;
     82         case StackLayer::Notification: windows = &m_notification; break;
     83         default: Util::die("no associated layer");
     84         }
     85 
     86         Util::erase_remove(*windows, window);
     87         windows->push_back(window);
     88     }
     89 }
     90 
     91 
     92 void
     93 StackHandler::add_above_other(winsys::Window window, winsys::Window sibling)
     94 {
     95     if (!(m_above_other.count(window) > 0))
     96         m_above_other[window] = sibling;
     97 }
     98 
     99 void
    100 StackHandler::add_below_other(winsys::Window window, winsys::Window sibling)
    101 {
    102     if (!(m_below_other.count(window) > 0))
    103         m_below_other[window] = sibling;
    104 }
    105 
    106 
    107 std::vector<winsys::Window> const&
    108 StackHandler::get_layer(StackLayer layer) const
    109 {
    110     switch (layer) {
    111     case StackLayer::Desktop:      return m_desktop;      break;
    112     case StackLayer::Below_:       return m_below;        break;
    113     case StackLayer::Dock:         return m_dock;         break;
    114     case StackLayer::Above_:       return m_above;        break;
    115     case StackLayer::Notification: return m_notification; break;
    116     default: Util::die("no associated layer");
    117     }
    118 
    119     return get_layer(StackLayer::Desktop);
    120 }