|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <unordered_map> |
| 4 | +#include <memory> |
| 5 | + |
| 6 | +#include "plugin.hpp" |
| 7 | +#include "timedrevealer.hpp" |
| 8 | +#include "lockergrid.hpp" |
| 9 | + |
| 10 | +template<class WidgetT> |
| 11 | +class WayfireLockerMultiOutputPlugin : public WayfireLockerPlugin |
| 12 | +{ |
| 13 | + protected: |
| 14 | + std::unordered_map<std::string, std::shared_ptr<WidgetT>> widgets; |
| 15 | + bool shown = true; |
| 16 | + |
| 17 | + virtual std::shared_ptr<WidgetT> create_widget() = 0; |
| 18 | + |
| 19 | + public: |
| 20 | + WayfireLockerMultiOutputPlugin(std::string prefix) : |
| 21 | + WayfireLockerPlugin(prefix) |
| 22 | + {} |
| 23 | + |
| 24 | + void add_output(std::string id, std::shared_ptr<WayfireLockerGrid> grid) override |
| 25 | + { |
| 26 | + auto widget = create_widget(); |
| 27 | + widgets.emplace(id, widget); |
| 28 | + |
| 29 | + if (!shown) |
| 30 | + { |
| 31 | + widget->hide(); |
| 32 | + } |
| 33 | + |
| 34 | + grid->attach(*widget, position); |
| 35 | + } |
| 36 | + |
| 37 | + void remove_output(std::string id, std::shared_ptr<WayfireLockerGrid> grid) override |
| 38 | + { |
| 39 | + auto it = widgets.find(id); |
| 40 | + if (it == widgets.end()) |
| 41 | + { |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + grid->remove(*it->second); |
| 46 | + widgets.erase(it); |
| 47 | + } |
| 48 | + |
| 49 | + void hide() |
| 50 | + { |
| 51 | + shown = false; |
| 52 | + for (auto& it : widgets) |
| 53 | + { |
| 54 | + it.second->hide(); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + void show() |
| 59 | + { |
| 60 | + shown = true; |
| 61 | + for (auto& it : widgets) |
| 62 | + { |
| 63 | + it.second->show(); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + void init() override |
| 68 | + {} |
| 69 | + void deinit() override |
| 70 | + {} |
| 71 | +}; |
| 72 | + |
| 73 | +template<class InnerWidgetT> |
| 74 | +class WayfireLockerTimedWidget : public WayfireLockerTimedRevealer |
| 75 | +{ |
| 76 | + public: |
| 77 | + InnerWidgetT inner; |
| 78 | + |
| 79 | + WayfireLockerTimedWidget(std::string always_option, const char *css_class = nullptr) : |
| 80 | + WayfireLockerTimedRevealer(always_option), |
| 81 | + inner("locker") |
| 82 | + { |
| 83 | + set_child(inner); |
| 84 | + if (css_class != nullptr) |
| 85 | + { |
| 86 | + inner.add_css_class(css_class); |
| 87 | + } |
| 88 | + } |
| 89 | +}; |
0 commit comments