-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenRGBEffectsPlugin-KeypressRipple.patch
More file actions
700 lines (700 loc) · 23.9 KB
/
Copy pathOpenRGBEffectsPlugin-KeypressRipple.patch
File metadata and controls
700 lines (700 loc) · 23.9 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
diff --git a/Effects/KeypressRipple/KeypressRipple.cpp b/Effects/KeypressRipple/KeypressRipple.cpp
new file mode 100644
index 0000000..2cb2309
--- /dev/null
+++ b/Effects/KeypressRipple/KeypressRipple.cpp
@@ -0,0 +1,547 @@
+/*---------------------------------------------------------*\
+| KeypressRipple.cpp |
+| |
+| Global keypress ripple effect for matrix keyboards |
+| |
+| This file is part of the OpenRGB Effects Plugin project|
+| SPDX-License-Identifier: GPL-2.0-or-later |
+\*---------------------------------------------------------*/
+
+#include "KeypressRipple.h"
+
+#include <algorithm>
+#include <cmath>
+#include <QGridLayout>
+
+REGISTER_EFFECT(KeypressRipple);
+
+#ifdef _WIN32
+thread_local KeypressRipple* KeypressRipple::hook_owner = nullptr;
+#endif
+
+KeypressRipple::KeypressRipple(QWidget* parent) :
+ RGBEffect(parent),
+ background_picker(new ColorPicker(this)),
+ lifetime_slider(new QSlider(Qt::Horizontal, this)),
+ lifetime_value(new QLabel(this)),
+ core_slider(new QSlider(Qt::Horizontal, this)),
+ core_value(new QLabel(this)),
+ listener_status(new QLabel(this)),
+ background(ToRGBColor(3, 0, 8)),
+ wave_speed(17),
+ wave_width_tenths(12),
+ lifetime_hundredths(115),
+ core_size_tenths(17),
+ random_colors(false),
+ ripple_colors
+ ({
+ ToRGBColor(0, 229, 255),
+ ToRGBColor(122, 0, 255),
+ ToRGBColor(255, 20, 147),
+ ToRGBColor(0, 255, 136),
+ ToRGBColor(255, 176, 0)
+ }),
+ next_color(0)
+#ifdef _WIN32
+ , listener_thread_id(0),
+ listener_ready(false),
+ listener_error(ERROR_SUCCESS)
+#endif
+{
+ EffectDetails.EffectClassName = ClassName();
+ EffectDetails.EffectName = tr(UI_Name().c_str()).toStdString();
+ EffectDetails.EffectDescription = tr("Color waves spread from every pressed key and overlap").toStdString();
+ EffectDetails.HasCustomSettings = true;
+ EffectDetails.ExpandCustomSettings = false;
+ EffectDetails.MinSpeed = 5;
+ EffectDetails.MaxSpeed = 30;
+ EffectDetails.MinSlider2Val = 5;
+ EffectDetails.MaxSlider2Val = 30;
+ EffectDetails.Slider2Name = QT_TR_NOOP("Wave width");
+ EffectDetails.UserColors = 5;
+ EffectDetails.SupportsRandom = true;
+
+ FPS = 30;
+ Speed = wave_speed.load();
+ Slider2Val = wave_width_tenths.load();
+ UserColors = ripple_colors;
+ RandomColorsEnabled = false;
+
+ background_picker->SetRGBColor(background.load());
+ lifetime_slider->setRange(50, 200);
+ lifetime_slider->setValue((int)lifetime_hundredths.load());
+ lifetime_value->setText(QString::number(lifetime_hundredths.load() / 100.0, 'f', 2) + " s");
+ core_slider->setRange(5, 35);
+ core_slider->setValue((int)core_size_tenths.load());
+ core_value->setText(QString::number(core_size_tenths.load() / 10.0, 'f', 1));
+#ifdef _WIN32
+ listener_status->setText(tr("Listener starts with the effect"));
+#else
+ listener_status->setText(tr("The key listener is currently available on Windows only"));
+#endif
+
+ QGridLayout* layout = new QGridLayout(this);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->addWidget(new QLabel(tr("Background:"), this), 0, 0);
+ layout->addWidget(background_picker, 0, 1);
+ layout->addWidget(new QLabel(tr("Lifetime:"), this), 1, 0);
+ layout->addWidget(lifetime_slider, 1, 1);
+ layout->addWidget(lifetime_value, 1, 2);
+ layout->addWidget(new QLabel(tr("Center flash size:"), this), 2, 0);
+ layout->addWidget(core_slider, 2, 1);
+ layout->addWidget(core_value, 2, 2);
+ layout->addWidget(listener_status, 3, 0, 1, 3);
+
+ connect(background_picker, &ColorPicker::ColorSelected, [this](QColor color)
+ {
+ background.store(ColorUtils::fromQColor(color));
+ });
+ connect(lifetime_slider, &QSlider::valueChanged, [this](int value)
+ {
+ lifetime_hundredths.store((unsigned int)value);
+ lifetime_value->setText(QString::number(value / 100.0, 'f', 2) + " s");
+ });
+ connect(core_slider, &QSlider::valueChanged, [this](int value)
+ {
+ core_size_tenths.store((unsigned int)value);
+ core_value->setText(QString::number(value / 10.0, 'f', 1));
+ });
+}
+
+KeypressRipple::~KeypressRipple()
+{
+ StopKeyboardListener();
+}
+
+void KeypressRipple::EffectState(bool enabled)
+{
+ EffectEnabled = enabled;
+ if(enabled)
+ {
+ StartKeyboardListener();
+ }
+ else
+ {
+ StopKeyboardListener();
+ }
+}
+
+void KeypressRipple::SetSpeed(unsigned int value)
+{
+ Speed = value;
+ wave_speed.store(value);
+}
+
+unsigned int KeypressRipple::GetSpeed()
+{
+ return wave_speed.load();
+}
+
+void KeypressRipple::SetSlider2Val(unsigned int value)
+{
+ Slider2Val = value;
+ wave_width_tenths.store(value);
+}
+
+unsigned int KeypressRipple::GetSlider2Val()
+{
+ return wave_width_tenths.load();
+}
+
+void KeypressRipple::SetUserColors(std::vector<RGBColor> colors)
+{
+ std::lock_guard<std::mutex> lock(colors_mutex);
+ ripple_colors = colors;
+ UserColors = colors;
+}
+
+std::vector<RGBColor> KeypressRipple::GetUserColors()
+{
+ std::lock_guard<std::mutex> lock(colors_mutex);
+ return ripple_colors;
+}
+
+void KeypressRipple::SetRandomColorsEnabled(bool value)
+{
+ RandomColorsEnabled = value;
+ random_colors.store(value);
+}
+
+bool KeypressRipple::IsRandomColorsEnabled()
+{
+ return random_colors.load();
+}
+
+void KeypressRipple::LoadCustomSettings(json settings)
+{
+ if(settings.contains("background"))
+ {
+ RGBColor color = settings["background"];
+ background.store(color);
+ background_picker->SetRGBColor(color);
+ }
+ if(settings.contains("lifetime_hundredths"))
+ {
+ lifetime_slider->setValue(settings["lifetime_hundredths"]);
+ }
+ if(settings.contains("core_size_tenths"))
+ {
+ core_slider->setValue(settings["core_size_tenths"]);
+ }
+}
+
+json KeypressRipple::SaveCustomSettings()
+{
+ json settings;
+ settings["background"] = background.load();
+ settings["lifetime_hundredths"] = lifetime_hundredths.load();
+ settings["core_size_tenths"] = core_size_tenths.load();
+ return settings;
+}
+
+RGBColor KeypressRipple::ScreenAdd(RGBColor base, RGBColor added, float strength)
+{
+ strength = std::clamp(strength, 0.0f, 1.0f);
+ auto channel = [strength](unsigned char a, unsigned char b)
+ {
+ float scaled = b * strength;
+ return (unsigned char)std::clamp((int)std::lround(255.0f - ((255.0f - a) * (255.0f - scaled) / 255.0f)), 0, 255);
+ };
+ return ToRGBColor
+ (
+ channel(RGBGetRValue(base), RGBGetRValue(added)),
+ channel(RGBGetGValue(base), RGBGetGValue(added)),
+ channel(RGBGetBValue(base), RGBGetBValue(added))
+ );
+}
+
+void KeypressRipple::StepEffect(std::vector<ControllerZone*> controller_zones)
+{
+ const auto now = std::chrono::steady_clock::now();
+ std::vector<PendingPress> new_presses;
+ {
+ std::lock_guard<std::mutex> lock(presses_mutex);
+ new_presses.swap(pending_presses);
+ }
+
+ std::vector<RGBColor> colors = GetUserColors();
+ for(const PendingPress& press : new_presses)
+ {
+ RGBColor color;
+ if(random_colors.load())
+ {
+ color = ColorUtils::RandomRGBColor();
+ }
+ else if(!colors.empty())
+ {
+ color = colors[next_color++ % colors.size()];
+ }
+ else
+ {
+ color = ToRGBColor(0, 229, 255);
+ }
+ pulses.push_back({press.born, press.led_idx, color});
+ }
+
+ const float lifetime = lifetime_hundredths.load() / 100.0f;
+ pulses.erase
+ (
+ std::remove_if(pulses.begin(), pulses.end(), [now, lifetime](const Pulse& pulse)
+ {
+ return std::chrono::duration<float>(now - pulse.born).count() >= lifetime;
+ }),
+ pulses.end()
+ );
+ if(pulses.size() > 48)
+ {
+ pulses.erase(pulses.begin(), pulses.end() - 48);
+ }
+
+ const float speed = (float)wave_speed.load();
+ const float width = wave_width_tenths.load() / 10.0f;
+ const float core_size = core_size_tenths.load() / 10.0f;
+ const RGBColor base_color = background.load();
+
+ for(ControllerZone* zone : controller_zones)
+ {
+ if(zone->type() != ZONE_TYPE_MATRIX)
+ {
+ continue;
+ }
+
+ const unsigned int cols = zone->matrix_map_width();
+ const unsigned int rows = zone->matrix_map_height();
+ const unsigned int* map = zone->map();
+ if(cols == 0 || rows == 0 || map == nullptr)
+ {
+ continue;
+ }
+
+ struct RenderPulse
+ {
+ float x;
+ float y;
+ float age;
+ RGBColor color;
+ };
+ std::vector<RenderPulse> render_pulses;
+ render_pulses.reserve(pulses.size());
+
+ for(const Pulse& pulse : pulses)
+ {
+ bool found = false;
+ for(unsigned int y = 0; y < rows && !found; y++)
+ {
+ for(unsigned int x = 0; x < cols; x++)
+ {
+ if(map[y * cols + x] == pulse.led_idx)
+ {
+ render_pulses.push_back
+ ({
+ (float)x,
+ y * 1.35f,
+ std::chrono::duration<float>(now - pulse.born).count(),
+ pulse.color
+ });
+ found = true;
+ break;
+ }
+ }
+ }
+ }
+
+ for(unsigned int y = 0; y < rows; y++)
+ {
+ for(unsigned int x = 0; x < cols; x++)
+ {
+ const unsigned int led_idx = map[y * cols + x];
+ if(led_idx == 0xFFFFFFFF)
+ {
+ continue;
+ }
+
+ RGBColor color = base_color;
+ const float led_y = y * 1.35f;
+ for(const RenderPulse& pulse : render_pulses)
+ {
+ if(pulse.age < 0.0f || pulse.age >= lifetime)
+ {
+ continue;
+ }
+ const float dx = x - pulse.x;
+ const float dy = led_y - pulse.y;
+ const float distance = std::sqrt(dx * dx + dy * dy);
+ const float radius = pulse.age * speed;
+ const float ring_delta = (distance - radius) / width;
+ const float fade = std::pow(1.0f - pulse.age / lifetime, 1.35f);
+ const float ring = std::exp(-0.5f * ring_delta * ring_delta) * fade;
+ const float core_delta = distance / core_size;
+ const float core = std::exp(-0.5f * core_delta * core_delta) * std::exp(-pulse.age * 7.5f);
+ color = ScreenAdd(color, pulse.color, std::min(1.0f, ring + core * 1.15f));
+ }
+ zone->SetLED((int)led_idx, color, Brightness, Temperature, Tint);
+ }
+ }
+ }
+}
+
+bool KeypressRipple::LogicalLEDFromScanCode(unsigned int scan, bool extended, unsigned int& led)
+{
+ if(!extended)
+ {
+ if(scan >= 0x3B && scan <= 0x44) { led = 1 + (scan - 0x3B); return true; }
+ if(scan >= 0x02 && scan <= 0x0B) { led = 17 + (scan - 0x02); return true; }
+ if(scan >= 0x10 && scan <= 0x19) { led = 38 + (scan - 0x10); return true; }
+ if(scan >= 0x1E && scan <= 0x26) { led = 59 + (scan - 0x1E); return true; }
+ if(scan >= 0x2C && scan <= 0x32) { led = 75 + (scan - 0x2C); return true; }
+ switch(scan)
+ {
+ case 0x01: led = 0; return true;
+ case 0x57: led = 11; return true;
+ case 0x58: led = 12; return true;
+ case 0x46: led = 14; return true;
+ case 0x29: led = 16; return true;
+ case 0x0C: led = 27; return true;
+ case 0x0D: led = 28; return true;
+ case 0x0E: led = 29; return true;
+ case 0x45: led = 33; return true;
+ case 0x37: led = 35; return true;
+ case 0x4A: led = 36; return true;
+ case 0x0F: led = 37; return true;
+ case 0x1A: led = 48; return true;
+ case 0x1B: led = 49; return true;
+ case 0x2B: led = 50; return true;
+ case 0x47: led = 54; return true;
+ case 0x48: led = 55; return true;
+ case 0x49: led = 56; return true;
+ case 0x4E: led = 57; return true;
+ case 0x3A: led = 58; return true;
+ case 0x27: led = 68; return true;
+ case 0x28: led = 69; return true;
+ case 0x1C: led = 70; return true;
+ case 0x4B: led = 71; return true;
+ case 0x4C: led = 72; return true;
+ case 0x4D: led = 73; return true;
+ case 0x2A: led = 74; return true;
+ case 0x33: led = 82; return true;
+ case 0x34: led = 83; return true;
+ case 0x35: led = 84; return true;
+ case 0x36: led = 85; return true;
+ case 0x4F: led = 87; return true;
+ case 0x50: led = 88; return true;
+ case 0x51: led = 89; return true;
+ case 0x1D: led = 91; return true;
+ case 0x38: led = 93; return true;
+ case 0x39: led = 94; return true;
+ case 0x52: led = 102; return true;
+ case 0x53: led = 103; return true;
+ default: return false;
+ }
+ }
+
+ switch(scan)
+ {
+ case 0x37: led = 13; return true;
+ case 0x45: led = 15; return true;
+ case 0x52: led = 30; return true;
+ case 0x47: led = 31; return true;
+ case 0x49: led = 32; return true;
+ case 0x35: led = 34; return true;
+ case 0x53: led = 51; return true;
+ case 0x4F: led = 52; return true;
+ case 0x51: led = 53; return true;
+ case 0x48: led = 86; return true;
+ case 0x1C: led = 90; return true;
+ case 0x5B: led = 92; return true;
+ case 0x38: led = 95; return true;
+ case 0x5D: led = 97; return true;
+ case 0x1D: led = 98; return true;
+ case 0x4B: led = 99; return true;
+ case 0x50: led = 100; return true;
+ case 0x4D: led = 101; return true;
+ default: return false;
+ }
+}
+
+#ifdef _WIN32
+LRESULT CALLBACK KeypressRipple::LowLevelKeyboardProc(int code, WPARAM message, LPARAM data)
+{
+ if(code >= 0 && hook_owner != nullptr)
+ {
+ const KBDLLHOOKSTRUCT* event = reinterpret_cast<const KBDLLHOOKSTRUCT*>(data);
+ const bool extended = (event->flags & LLKHF_EXTENDED) != 0;
+ if(message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
+ {
+ hook_owner->QueueScanCode(event->scanCode, extended, true);
+ }
+ else if(message == WM_KEYUP || message == WM_SYSKEYUP)
+ {
+ hook_owner->QueueScanCode(event->scanCode, extended, false);
+ }
+ }
+ return CallNextHookEx(nullptr, code, message, data);
+}
+
+void KeypressRipple::QueueScanCode(unsigned int scan_code, bool extended, bool key_down)
+{
+ const unsigned int physical = scan_code | (extended ? 0x100u : 0u);
+ if(!key_down)
+ {
+ pressed_scan_codes.erase(physical);
+ return;
+ }
+ if(!pressed_scan_codes.insert(physical).second)
+ {
+ return;
+ }
+
+ unsigned int led_idx;
+ if(LogicalLEDFromScanCode(scan_code, extended, led_idx))
+ {
+ std::lock_guard<std::mutex> lock(presses_mutex);
+ pending_presses.push_back({std::chrono::steady_clock::now(), led_idx});
+ }
+}
+
+void KeypressRipple::StartKeyboardListener()
+{
+ if(listener_thread.joinable())
+ {
+ return;
+ }
+ {
+ std::lock_guard<std::mutex> lock(listener_state_mutex);
+ listener_ready = false;
+ listener_error = ERROR_SUCCESS;
+ }
+ listener_thread = std::thread(&KeypressRipple::KeyboardListenerThread, this);
+
+ std::unique_lock<std::mutex> lock(listener_state_mutex);
+ listener_ready_condition.wait_for(lock, std::chrono::seconds(3), [this](){ return listener_ready; });
+ if(listener_error == ERROR_SUCCESS)
+ {
+ listener_status->setText(tr("Listener active — press any key"));
+ }
+ else
+ {
+ listener_status->setText(tr("Listener error: ") + QString::number(listener_error));
+ }
+}
+
+void KeypressRipple::StopKeyboardListener()
+{
+ DWORD thread_id = listener_thread_id.load();
+ if(thread_id != 0)
+ {
+ PostThreadMessageW(thread_id, WM_QUIT, 0, 0);
+ }
+ if(listener_thread.joinable())
+ {
+ listener_thread.join();
+ }
+ listener_thread_id.store(0);
+ listener_status->setText(tr("Listener stopped"));
+ {
+ std::lock_guard<std::mutex> lock(presses_mutex);
+ pending_presses.clear();
+ }
+}
+
+void KeypressRipple::KeyboardListenerThread()
+{
+ listener_thread_id.store(GetCurrentThreadId());
+ hook_owner = this;
+
+ MSG message;
+ PeekMessageW(&message, nullptr, WM_USER, WM_USER, PM_NOREMOVE);
+ HHOOK hook = SetWindowsHookExW(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandleW(nullptr), 0);
+ {
+ std::lock_guard<std::mutex> lock(listener_state_mutex);
+ listener_error = hook == nullptr ? GetLastError() : ERROR_SUCCESS;
+ listener_ready = true;
+ }
+ listener_ready_condition.notify_all();
+
+ if(hook != nullptr)
+ {
+ while(GetMessageW(&message, nullptr, 0, 0) > 0)
+ {
+ TranslateMessage(&message);
+ DispatchMessageW(&message);
+ }
+ UnhookWindowsHookEx(hook);
+ }
+
+ pressed_scan_codes.clear();
+ hook_owner = nullptr;
+}
+#else
+void KeypressRipple::StartKeyboardListener()
+{
+ listener_status->setText(tr("The key listener is currently available on Windows only"));
+}
+
+void KeypressRipple::StopKeyboardListener()
+{
+}
+#endif
diff --git a/Effects/KeypressRipple/KeypressRipple.h b/Effects/KeypressRipple/KeypressRipple.h
new file mode 100644
index 0000000..f2bc9d7
--- /dev/null
+++ b/Effects/KeypressRipple/KeypressRipple.h
@@ -0,0 +1,121 @@
+/*---------------------------------------------------------*\
+| KeypressRipple.h |
+| |
+| Global keypress ripple effect for matrix keyboards |
+| |
+| This file is part of the OpenRGB Effects Plugin project|
+| SPDX-License-Identifier: GPL-2.0-or-later |
+\*---------------------------------------------------------*/
+
+#pragma once
+
+#include <atomic>
+#include <chrono>
+#include <condition_variable>
+#include <cstdint>
+#include <mutex>
+#include <thread>
+#include <unordered_set>
+#include <vector>
+
+#include <QLabel>
+#include <QSlider>
+#include <QWidget>
+
+#include "ColorPicker.h"
+#include "EffectRegisterer.h"
+#include "RGBEffect.h"
+
+#ifdef _WIN32
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+#include <windows.h>
+#endif
+
+class KeypressRipple : public RGBEffect
+{
+public:
+ explicit KeypressRipple(QWidget* parent = nullptr);
+ ~KeypressRipple() override;
+
+ EFFECT_REGISTERER(ClassName(), UI_Name(), CAT_SPECIAL, [](){ return new KeypressRipple; });
+
+ static std::string const ClassName() { return "KeypressRipple"; }
+ static std::string const UI_Name() { return QT_TR_NOOP("Keypress Ripple"); }
+
+ void EffectState(bool enabled) override;
+ void StepEffect(std::vector<ControllerZone*> controller_zones) override;
+
+ void SetSpeed(unsigned int value) override;
+ unsigned int GetSpeed() override;
+ void SetSlider2Val(unsigned int value) override;
+ unsigned int GetSlider2Val() override;
+ void SetUserColors(std::vector<RGBColor> colors) override;
+ std::vector<RGBColor> GetUserColors() override;
+ void SetRandomColorsEnabled(bool value) override;
+ bool IsRandomColorsEnabled() override;
+
+ void LoadCustomSettings(json settings) override;
+ json SaveCustomSettings() override;
+
+private:
+ struct PendingPress
+ {
+ std::chrono::steady_clock::time_point born;
+ unsigned int led_idx;
+ };
+
+ struct Pulse
+ {
+ std::chrono::steady_clock::time_point born;
+ unsigned int led_idx;
+ RGBColor color;
+ };
+
+ ColorPicker* background_picker;
+ QSlider* lifetime_slider;
+ QLabel* lifetime_value;
+ QSlider* core_slider;
+ QLabel* core_value;
+ QLabel* listener_status;
+
+ std::atomic<RGBColor> background;
+ std::atomic<unsigned int> wave_speed;
+ std::atomic<unsigned int> wave_width_tenths;
+ std::atomic<unsigned int> lifetime_hundredths;
+ std::atomic<unsigned int> core_size_tenths;
+ std::atomic<bool> random_colors;
+
+ mutable std::mutex colors_mutex;
+ std::vector<RGBColor> ripple_colors;
+ unsigned int next_color;
+
+ std::mutex presses_mutex;
+ std::vector<PendingPress> pending_presses;
+ std::vector<Pulse> pulses;
+
+#ifdef _WIN32
+ static thread_local KeypressRipple* hook_owner;
+ static LRESULT CALLBACK LowLevelKeyboardProc(int code, WPARAM message, LPARAM data);
+
+ void StartKeyboardListener();
+ void StopKeyboardListener();
+ void KeyboardListenerThread();
+ void QueueScanCode(unsigned int scan_code, bool extended, bool key_down);
+
+ std::thread listener_thread;
+ std::atomic<DWORD> listener_thread_id;
+ std::mutex listener_state_mutex;
+ std::condition_variable listener_ready_condition;
+ bool listener_ready;
+ DWORD listener_error;
+ std::unordered_set<unsigned int> pressed_scan_codes;
+#else
+ void StartKeyboardListener();
+ void StopKeyboardListener();
+#endif
+
+ static bool LogicalLEDFromScanCode(unsigned int scan_code, bool extended, unsigned int& led_idx);
+ static RGBColor ScreenAdd(RGBColor base, RGBColor added, float strength);
+};
diff --git a/OpenRGBEffectsPlugin.pro b/OpenRGBEffectsPlugin.pro
index 0ebfc42..582e90b 100644
--- a/OpenRGBEffectsPlugin.pro
+++ b/OpenRGBEffectsPlugin.pro
@@ -339,6 +339,7 @@ SOURCES +=
Effects/GifPlayer/GifPlayer.cpp \
Effects/GradientWave/GradientWave.cpp \
Effects/Hypnotoad/Hypnotoad.cpp \
+ Effects/KeypressRipple/KeypressRipple.cpp \
Effects/Layers/Layers.cpp \
Effects/Layers/LayerEntry.cpp \
Effects/Layers/LayerGroupEntry.cpp \
@@ -411,6 +412,7 @@ HEADERS +=
Effects/GifPlayer/GifPlayer.h \
Effects/GradientWave/GradientWave.h \
Effects/Hypnotoad/Hypnotoad.h \
+ Effects/KeypressRipple/KeypressRipple.h \
Effects/Layers/Layers.h \
Effects/Layers/LayerEntry.h \
Effects/Layers/LayerGroupEntry.h \