-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathget_msg_proc.hh
107 lines (95 loc) · 3.07 KB
/
get_msg_proc.hh
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
// -*- mode: c++; coding: utf-8 -*-
// This file is part of
// Emulator of GNU Emacs IME patch for Windows (tr-ime)
// https://github.com/trueroad/tr-emacs-ime-module
//
// Copyright (C) 2020, 2022 Masamichi Hosoda
//
// Emulator of GNU Emacs IME patch for Windows (tr-ime)
// is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Emulator of GNU Emacs IME patch for Windows (tr-ime)
// is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with tr-ime.
// If not, see <https://www.gnu.org/licenses/>.
#ifndef INCLUDE_GUARD_GET_MSG_PROC_HH
#define INCLUDE_GUARD_GET_MSG_PROC_HH
#include <atomic>
#include <unordered_set>
#include <windows.h>
class get_msg_proc final
{
public:
static LRESULT CALLBACK proc (int, WPARAM, LPARAM);
static void destroy (HWND hwnd)
{
remove_hwnd (hwnd);
remove_exclude_hwnd (hwnd);
}
static void set_b_dispatch_thread_messages (bool bset)
{
ab_dispatch_thread_messages_.store (bset);
}
static void set_b_dispatch_thread_wm_timer (bool bset)
{
ab_dispatch_thread_wm_timer_.store (bset);
}
explicit get_msg_proc () = delete;
~get_msg_proc () = delete;
get_msg_proc (const get_msg_proc &) = delete;
get_msg_proc (get_msg_proc &&) = delete;
get_msg_proc& operator = (const get_msg_proc &) = delete;
get_msg_proc& operator = (get_msg_proc &&) = delete;
private:
static bool find_hwnd (HWND hwnd)
{
return (hwnds_.find (hwnd) != hwnds_.end ());
}
static void add_hwnd (HWND hwnd)
{
hwnds_.insert (hwnd);
}
static void remove_hwnd (HWND hwnd)
{
hwnds_.erase (hwnd);
}
static bool find_exclude_hwnd (HWND hwnd)
{
return (exclude_hwnds_.find (hwnd) != exclude_hwnds_.end ());
}
static void add_exclude_hwnd (HWND hwnd)
{
exclude_hwnds_.insert (hwnd);
}
static void remove_exclude_hwnd (HWND hwnd)
{
exclude_hwnds_.erase (hwnd);
}
static bool get_b_dispatch_thread_messages (void)
{
return ab_dispatch_thread_messages_.load ();
}
static bool get_b_dispatch_thread_wm_timer (void)
{
return ab_dispatch_thread_wm_timer_.load ();
}
static LRESULT wm_tr_ime_subclassify (int, WPARAM, LPARAM);
static LRESULT wm_tr_ime_unsubclassify (int, WPARAM, LPARAM);
static LRESULT wm_tr_ime_exists_subclassified (int, WPARAM, LPARAM);
static bool is_target_class (HWND);
static constexpr WCHAR target_class_name_[] {L"Emacs"};
static thread_local bool bsubclassify_all_;
static thread_local std::unordered_set<HWND> hwnds_;
static thread_local std::unordered_set<HWND> exclude_hwnds_;
static std::atomic<bool> ab_dispatch_thread_messages_;
static std::atomic<bool> ab_dispatch_thread_wm_timer_;
};
#endif // INCLUDE_GUARD_GET_MSG_PROC_HH