aboutsummaryrefslogtreecommitdiff
path: root/src/WindowActionRouter.hpp
blob: cfb25da23d86e27bf45b5ea84c06665b2ce43ae4 (plain) (blame)
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
#pragma once

#include <QWidget>
#include <QtCore>
#include <cstdint>
#include <functional>
#include <mutex>

#include "EventQueue.hpp"
#include "widgets/BrowserWindow.hpp"
#include "widgets/WebViewStack.hpp"

#define WITH_WEBVIEW_WINDOW(WEBVIEW_ID, IDENT, BLOCK)                                              \
  for (auto &win_match : window_map) {                                                             \
    auto *IDENT = win_match.second;                                                                \
    if (IDENT->mediator()->has_webview(WEBVIEW_ID)) {                                              \
      BLOCK;                                                                                       \
    }                                                                                              \
  }

class WindowActionRouter : public QWidget {
  Q_OBJECT

public:
  static WindowActionRouter &instance() {
    static WindowActionRouter router;
    return router;
  }

  void initialize();

  void add_window(BrowserWindow *window);
  const WindowMap &windows();

  WebViewId fetch_current_view_id(WindowId win_id = 0);
  QList<WebViewData> fetch_webview_data_list(WindowId win_id = 0);

  DELEGATE((&event_queue), dispatch_event, dispatch_event);
  DELEGATE((&event_queue), register_event, register_event)

protected:
  WindowActionRouter() = default;

  void add_keymap(const QString &mode_string, const QString &keyseq, std::function<void()> action);

signals:
  void new_window_requested(const QUrl &url);

private:
  std::mutex window_map_mutex;
  WindowMap window_map;
  uint64_t last_id = 1;
  Configuration *configuration;

  EventQueue event_queue;
};