rust_widgets 1.1.3

Pure Rust cross-platform native GUI library with hardware-adaptive rendering, 60+ widgets, touch/gesture support, i18n, and SVG-pipeline-accurate output
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
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
// SPDX-FileCopyrightText: Copyright (c) 2026 Mike Li/Mikewolfli/Wei Li(mikewolfli@163.com)
// SPDX-License-Identifier: MIT

use super::types::{LinuxHandleKind, LinuxPlatform};
use crate::compat::OnceLock;
#[cfg(all(target_os = "linux", feature = "gtk-native"))]
use crate::core::MutexExt;
use crate::core::PlatformFamily;
#[cfg(target_os = "linux")]
use crate::platform::accessibility::linux::LinuxAccessibilityBridge;
#[cfg(target_os = "linux")]
use crate::platform::accessibility::AccessibilityBridge;
use crate::platform::{DropEvent, Platform, WidgetTriggerEvent, WidgetTriggerKind};
#[cfg(all(target_os = "linux", feature = "gtk-native"))]
use gtk::prelude::*;
use std::sync::atomic::Ordering;
#[cfg(not(all(target_os = "linux", feature = "gtk-native")))]
use std::thread;
#[cfg(not(all(target_os = "linux", feature = "gtk-native")))]
use std::time::Duration;

impl Platform for LinuxPlatform {
    fn as_any(&self) -> &dyn std::any::Any {
        self
    }
    fn backend_name(&self) -> &'static str {
        #[cfg(all(target_os = "linux", feature = "gtk-native"))]
        {
            "gtk"
        }
        #[cfg(not(all(target_os = "linux", feature = "gtk-native")))]
        {
            // Honest name: without the `gtk-native` feature this backend keeps
            // widget state in-process and never opens native GTK windows.
            "linux-state-backend"
        }
    }
    fn family(&self) -> PlatformFamily {
        PlatformFamily::Desktop
    }

    /// Reads `MemTotal` from `/proc/meminfo` — the Linux kernel's own accounting
    /// of installed physical memory.
    fn total_memory_mb(&self) -> Option<u64> {
        let content = std::fs::read_to_string("/proc/meminfo").ok()?;
        for line in content.lines() {
            let Some(rest) = line.strip_prefix("MemTotal:") else {
                continue;
            };
            let kb = rest.trim().trim_end_matches("kB").trim().parse::<u64>().ok()?;
            return Some(kb / 1024);
        }
        None
    }

    /// Walks `/sys/class/power_supply` for a battery reporting `Discharging`.
    ///
    /// Machines with no battery (the common desktop/server case) simply find no
    /// matching entry and report `false`.
    fn is_on_battery(&self) -> bool {
        let Ok(entries) = std::fs::read_dir("/sys/class/power_supply") else {
            return false;
        };
        for entry in entries.flatten() {
            let status_path = entry.path().join("status");
            if let Ok(status) = std::fs::read_to_string(&status_path) {
                if status.trim() == "Discharging" {
                    return true;
                }
            }
        }
        false
    }

    /// Samples RSS/VmSize for this process from `/proc/self/status`.
    fn process_memory_utilization(&self) -> Option<f32> {
        let status = std::fs::read_to_string("/proc/self/status").ok()?;
        let mut vmrss_kb: u64 = 0;
        let mut vmsize_kb: u64 = 0;
        for line in status.lines() {
            if let Some(rest) = line.strip_prefix("VmRSS:") {
                vmrss_kb = rest.trim().trim_end_matches("kB").trim().parse().unwrap_or(0);
            } else if let Some(rest) = line.strip_prefix("VmSize:") {
                vmsize_kb = rest.trim().trim_end_matches("kB").trim().parse().unwrap_or(0);
            }
        }
        if vmsize_kb == 0 {
            return None;
        }
        Some((vmrss_kb as f32 / vmsize_kb as f32).clamp(0.0, 1.0))
    }

    /// Estimates CPU load as thread count over twice the available cores.
    fn process_cpu_utilization(&self) -> Option<f32> {
        let status = std::fs::read_to_string("/proc/self/status").ok()?;
        for line in status.lines() {
            let Some(rest) = line.strip_prefix("Threads:") else {
                continue;
            };
            let threads = rest.trim().parse::<f32>().ok()?;
            // A well-utilized 4-core system runs roughly 8 active threads.
            let cores = std::thread::available_parallelism().map(|n| n.get() as f32).unwrap_or(4.0);
            return Some((threads / (cores * 2.0)).clamp(0.0, 1.0));
        }
        None
    }

    /// Submits via `lpr`, falling back to `lp`.
    fn spawn_print_job(&self, job_file: &std::path::Path) -> Result<(), String> {
        if let Ok(status) = std::process::Command::new("lpr").arg(job_file).status() {
            if status.success() {
                return Ok(());
            }
        }
        if let Ok(status) = std::process::Command::new("lp").arg(job_file).status() {
            if status.success() {
                return Ok(());
            }
        }
        Err("no available system print command succeeded (tried: lpr, lp)".to_string())
    }

    /// `lp` or `lpr` must be present for the system print backend to work.
    fn has_print_support(&self) -> bool {
        crate::platform::types::unix_print_clients_available()
    }

    /// Hands back a real `webkit2gtk::WebView` wrapper when the `webkit-engine`
    /// feature is on and GTK can create one.
    ///
    /// `None` on a headless host or a build without the feature, which tells
    /// `src/web/` to use its simulated navigation path.
    #[cfg(all(
        target_os = "linux",
        feature = "webkit-engine",
        not(any(feature = "mini", feature = "embedded"))
    ))]
    fn create_web_engine(&self) -> Option<Box<dyn crate::platform::types::NativeWebEngine>> {
        super::webkit_engine::WebKitEngine::new()
            .map(|engine| Box::new(engine) as Box<dyn crate::platform::types::NativeWebEngine>)
    }

    /// A self-drawn widget gets a `gtk::DrawingArea` inside the window's content
    /// container; its `draw` signal blits a frame from `widget::runtime`.
    /// See `linux/canvas.rs`.
    ///
    /// Gated on the same profile conditions as `canvas.rs`: `mini`/`embedded`
    /// have no widget registry, so the trait defaults apply and
    /// `supports_self_drawn()` honestly reports `false`.
    #[cfg(not(any(feature = "mini", feature = "embedded")))]
    fn mount_self_drawn(
        &self,
        parent: crate::core::ObjectId,
        id: crate::core::ObjectId,
        rect: crate::core::Rect,
    ) -> bool {
        super::canvas::mount_canvas(self, parent, id, rect)
    }

    #[cfg(not(any(feature = "mini", feature = "embedded")))]
    fn resize_self_drawn(&self, id: crate::core::ObjectId, rect: crate::core::Rect) -> bool {
        super::canvas::resize_canvas(self, id, rect)
    }

    #[cfg(not(any(feature = "mini", feature = "embedded")))]
    fn unmount_self_drawn(&self, id: crate::core::ObjectId) -> bool {
        super::canvas::unmount_canvas(self, id)
    }

    /// `true` only when the self-drawn surface exists for this profile.
    #[cfg(not(any(feature = "mini", feature = "embedded")))]
    fn supports_self_drawn(&self) -> bool {
        true
    }

    /// Queue a redraw on the canvas's `DrawingArea`.
    #[cfg(not(any(feature = "mini", feature = "embedded")))]
    fn repaint_self_drawn(&self, id: crate::core::ObjectId) -> bool {
        super::canvas::repaint_canvas(self, id)
    }
    fn init(&self) {
        self.runtime.initialized.store(true, Ordering::SeqCst);
        #[cfg(all(target_os = "linux", feature = "gtk-native"))]
        {
            if let Err(e) = gtk::init() {
                log::error!("[linux] gtk::init() failed: {:?}", e);
            }
        }
        #[cfg(not(all(target_os = "linux", feature = "gtk-native")))]
        {}
    }
    fn run(&self) {
        #[cfg(all(target_os = "linux", feature = "gtk-native"))]
        {
            gtk::main();
        }
        #[cfg(not(all(target_os = "linux", feature = "gtk-native")))]
        {
            if !self.runtime.initialized.load(Ordering::SeqCst) {
                self.init();
            }
            self.runtime.running.store(true, Ordering::SeqCst);
            while self.runtime.running.load(Ordering::SeqCst) {
                thread::sleep(Duration::from_millis(16));
            }
        }
    }
    fn quit(&self) {
        self.runtime.running.store(false, Ordering::SeqCst);
        #[cfg(all(target_os = "linux", feature = "gtk-native"))]
        {
            gtk::main_quit();
        }
    }

    /// Release every registry entry the backend holds for `widget_id`.
    ///
    /// Beyond the authoritative `BackendState` record, the Linux backend keeps
    /// per-widget entries in three places: the shared list storage (`list_data`,
    /// used by ComboBox/ListBox), the menu bookkeeping (`menus`, covering the
    /// attachment map, the menu tree and the queued triggers) and — under
    /// `gtk-native` — the native GTK registries in `native` (plus the
    /// `widget_parent` link used for geometry updates). All must be purged,
    /// otherwise a UI rebuilt in a create/destroy loop would leak one entry per
    /// discarded widget. Every lock is scoped to its own statement so no two
    /// guards are ever held at the same time.
    ///
    /// Only the library's own bookkeeping is released here: no GTK call is made,
    /// and the native objects are dropped when their registry entries are removed
    /// (GTK keeps its own reference for objects still attached to a parent).
    fn destroy_widget(&self, widget_id: u64) -> bool {
        self.list_data.lock().expect("linux list data lock poisoned").remove(&widget_id);

        {
            let mut menus = self.menus.lock().expect("linux menu lock poisoned");
            // The widget may be an attached menu bar (keyed by window id) or a
            // window owning one, so both directions are cleared.
            menus.attached_menu_bar.remove(&widget_id);
            menus.attached_menu_bar.retain(|_, bar| *bar != widget_id);
            // The widget may be a container in the menu tree: drop both the
            // children it owned and the child entry under its own parent.
            menus.menu_children.remove(&widget_id);
            for children in menus.menu_children.values_mut() {
                children.retain(|child| *child != widget_id);
            }
            menus.widget_parent.remove(&widget_id);
            // Drop queued triggers that reference a widget that no longer exists.
            menus.pending_menu_events.retain(|queued| *queued != widget_id);
            menus.pending_widget_events.retain(|event| event.widget_id != widget_id);
        }

        #[cfg(all(target_os = "linux", feature = "gtk-native"))]
        {
            let mut native = self.native.lock_guard();
            native.windows.remove(&widget_id);
            native.root_boxes.remove(&widget_id);
            native.content_fixed.remove(&widget_id);
            native.widgets.remove(&widget_id);
            native.menu_bars.remove(&widget_id);
            native.menus.remove(&widget_id);
            native.dialogs.remove(&widget_id);
            native.color_choosers.remove(&widget_id);
            native.font_choosers.remove(&widget_id);
        }

        // The state record is the authority on whether the widget existed.
        self.state.destroy_widget(widget_id)
    }

    fn create_window(&self, title: &str, x: i32, y: i32, width: u32, height: u32) -> u64 {
        let id = self.insert_widget(LinuxHandleKind::Window, title, x, y, width, height);
        // A fresh GTK toplevel is restored, windowed, resizable and decorated.
        self.state.init_window_state(id, crate::platform::state::WindowStateRecord::new_window());
        #[cfg(all(target_os = "linux", feature = "gtk-native"))]
        {
            let window = gtk::Window::new(gtk::WindowType::Toplevel);
            window.set_title(title);
            window.set_default_size(width as i32, height as i32);
            window.move_(x, y);
            let root = gtk::Box::new(gtk::Orientation::Vertical, 0);
            let fixed = gtk::Fixed::new();
            root.pack_start(&fixed, true, true, 0);
            window.add(&root);
            let mut native = self.native.lock_guard();
            native.windows.insert(id, window.clone());
            native.root_boxes.insert(id, root);
            native.content_fixed.insert(id, fixed.clone());
            native.widgets.insert(id, window.clone().upcast::<gtk::Widget>());
        }
        id
    }

    // ── Widget creation methods ──
    fn create_button(
        &self,
        parent: u64,
        text: &str,
        x: i32,
        y: i32,
        width: u32,
        height: u32,
    ) -> u64 {
        self.create_button_impl(parent, text, x, y, width, height)
    }
    fn create_checkbox(
        &self,
        parent: u64,
        text: &str,
        x: i32,
        y: i32,
        width: u32,
        height: u32,
    ) -> u64 {
        self.create_checkbox_impl(parent, text, x, y, width, height)
    }
    fn create_line_edit(
        &self,
        parent: u64,
        text: &str,
        x: i32,
        y: i32,
        width: u32,
        height: u32,
    ) -> u64 {
        self.create_line_edit_impl(parent, text, x, y, width, height)
    }
    fn create_label(
        &self,
        parent: u64,
        text: &str,
        x: i32,
        y: i32,
        width: u32,
        height: u32,
    ) -> u64 {
        self.create_label_impl(parent, text, x, y, width, height)
    }
    fn create_radio_button(
        &self,
        parent: u64,
        text: &str,
        x: i32,
        y: i32,
        width: u32,
        height: u32,
    ) -> u64 {
        self.create_radio_button_impl(parent, text, x, y, width, height)
    }
    fn create_slider(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_slider_impl(parent, x, y, width, height)
    }
    fn create_progress_bar(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_progress_bar_impl(parent, x, y, width, height)
    }
    fn create_combo_box(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_combo_box_impl(parent, x, y, width, height)
    }
    fn create_list_box(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_list_box_impl(parent, x, y, width, height)
    }
    fn list_box_add_item(&self, list_box: u64, text: &str) -> bool {
        self.list_box_add_item_impl(list_box, text)
    }
    fn list_box_remove_item(&self, list_box: u64, index: usize) -> bool {
        self.list_box_remove_item_impl(list_box, index)
    }
    fn list_box_clear_items(&self, list_box: u64) -> bool {
        self.list_box_clear_items_impl(list_box)
    }
    fn list_box_set_current_index(&self, list_box: u64, index: usize) -> bool {
        self.list_box_set_current_index_impl(list_box, index)
    }
    fn list_box_current_index(&self, list_box: u64) -> Option<usize> {
        self.list_box_current_index_impl(list_box)
    }
    fn list_box_item_count(&self, list_box: u64) -> usize {
        self.list_box_item_count_impl(list_box)
    }
    fn list_box_item_text(&self, list_box: u64, index: usize) -> Option<String> {
        self.list_box_item_text_impl(list_box, index)
    }
    fn combo_box_add_item(&self, combo_box: u64, text: &str) -> bool {
        self.combo_box_add_item_impl(combo_box, text)
    }
    fn combo_box_clear_items(&self, combo_box: u64) -> bool {
        self.combo_box_clear_items_impl(combo_box)
    }
    fn combo_box_set_current_index(&self, combo_box: u64, index: usize) -> bool {
        self.combo_box_set_current_index_impl(combo_box, index)
    }
    fn combo_box_current_index(&self, combo_box: u64) -> Option<usize> {
        self.combo_box_current_index_impl(combo_box)
    }
    fn combo_box_item_count(&self, combo_box: u64) -> usize {
        self.combo_box_item_count_impl(combo_box)
    }
    fn combo_box_item_text(&self, combo_box: u64, index: usize) -> Option<String> {
        self.combo_box_item_text_impl(combo_box, index)
    }
    fn create_panel(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_panel_impl(parent, x, y, width, height)
    }
    fn create_spin_box(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_spin_box_impl(parent, x, y, width, height)
    }
    fn create_list_view(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_list_view_impl(parent, x, y, width, height)
    }
    fn create_scroll_area(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_scroll_area_impl(parent, x, y, width, height)
    }
    fn create_group_box(
        &self,
        parent: u64,
        title: &str,
        x: i32,
        y: i32,
        width: u32,
        height: u32,
    ) -> u64 {
        self.create_group_box_impl(parent, title, x, y, width, height)
    }
    fn create_frame(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_frame_impl(parent, x, y, width, height)
    }
    fn create_tab_widget(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_tab_widget_impl(parent, x, y, width, height)
    }
    fn create_splitter(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_splitter_impl(parent, x, y, width, height)
    }
    fn create_toggle_button(
        &self,
        parent: u64,
        text: &str,
        x: i32,
        y: i32,
        width: u32,
        height: u32,
    ) -> u64 {
        self.create_toggle_button_impl(parent, text, x, y, width, height)
    }
    fn create_calendar(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_calendar_impl(parent, x, y, width, height)
    }
    fn create_scroll_bar(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_scroll_bar_impl(parent, x, y, width, height)
    }
    fn create_double_spin_box(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_double_spin_box_impl(parent, x, y, width, height)
    }
    fn create_font_combo_box(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_font_combo_box_impl(parent, x, y, width, height)
    }
    fn create_context_menu(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_context_menu_impl(parent, x, y, width, height)
    }
    fn create_popup_window(
        &self,
        parent: u64,
        title: &str,
        x: i32,
        y: i32,
        width: u32,
        height: u32,
    ) -> u64 {
        self.create_popup_window_impl(parent, title, x, y, width, height)
    }
    fn create_dialog(
        &self,
        parent: u64,
        title: &str,
        x: i32,
        y: i32,
        width: u32,
        height: u32,
    ) -> u64 {
        self.create_dialog_impl(parent, title, x, y, width, height)
    }
    fn create_input_dialog(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_input_dialog_impl(parent, x, y, width, height)
    }
    fn create_progress_dialog(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_progress_dialog_impl(parent, x, y, width, height)
    }
    fn create_directory_dialog(
        &self,
        parent: u64,
        title: &str,
        x: i32,
        y: i32,
        width: u32,
        height: u32,
    ) -> u64 {
        self.create_directory_dialog_impl(parent, title, x, y, width, height)
    }
    fn create_date_picker(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_date_picker_impl(parent, x, y, width, height)
    }
    fn create_time_picker(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_time_picker_impl(parent, x, y, width, height)
    }
    fn create_date_time_picker(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_date_time_picker_impl(parent, x, y, width, height)
    }
    fn create_activity_indicator(
        &self,
        parent: u64,
        x: i32,
        y: i32,
        width: u32,
        height: u32,
    ) -> u64 {
        self.create_activity_indicator_impl(parent, x, y, width, height)
    }

    // ── Menu methods ──
    fn create_menu_bar(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_menu_bar_impl(parent, x, y, width, height)
    }
    fn create_menu(&self, parent: u64, text: &str, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_menu_impl(parent, text, x, y, width, height)
    }
    fn create_tool_bar(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_tool_bar_impl(parent, x, y, width, height)
    }
    fn create_status_bar(
        &self,
        parent: u64,
        text: &str,
        x: i32,
        y: i32,
        width: u32,
        height: u32,
    ) -> u64 {
        self.create_status_bar_impl(parent, text, x, y, width, height)
    }
    fn attach_menu_bar_to_window(&self, window: u64, menu_bar: u64) -> bool {
        self.attach_menu_bar_to_window_impl(window, menu_bar)
    }
    fn menu_add_item(&self, parent_menu: u64, text: &str, shortcut: Option<&str>) -> u64 {
        self.menu_add_item_impl(parent_menu, text, shortcut)
    }
    fn menu_item_shortcut(&self, menu_item: u64) -> Option<String> {
        self.menu_item_shortcut_impl(menu_item)
    }
    fn poll_menu_triggered(&self) -> Option<u64> {
        self.poll_menu_triggered_impl()
    }
    fn inject_menu_trigger(&self, menu_item_id: u64) -> bool {
        self.inject_menu_trigger_impl(menu_item_id)
    }
    fn poll_widget_triggered(&self) -> Option<u64> {
        self.poll_widget_triggered_impl()
    }
    fn poll_widget_trigger_event(&self) -> Option<WidgetTriggerEvent> {
        self.poll_widget_trigger_event_impl()
    }
    fn inject_widget_trigger_event(&self, widget_id: u64, kind: WidgetTriggerKind) -> bool {
        self.inject_widget_trigger_event_impl(widget_id, kind)
    }

    // ── Widget state methods ──
    fn show_widget(&self, widget_id: u64) {
        self.show_widget_impl(widget_id)
    }
    fn hide_widget(&self, widget_id: u64) {
        self.hide_widget_impl(widget_id)
    }
    fn set_widget_geometry(&self, widget_id: u64, x: i32, y: i32, width: u32, height: u32) {
        self.set_widget_geometry_impl(widget_id, x, y, width, height)
    }
    fn set_widget_text(&self, widget_id: u64, text: &str) {
        self.set_widget_text_impl(widget_id, text)
    }
    fn get_widget_text(&self, widget_id: u64) -> String {
        self.get_widget_text_impl(widget_id)
    }
    fn set_widget_enabled(&self, widget_id: u64, enabled: bool) {
        self.set_widget_enabled_impl(widget_id, enabled)
    }
    fn is_widget_enabled(&self, widget_id: u64) -> bool {
        self.is_widget_enabled_impl(widget_id)
    }
    fn set_widget_visible(&self, widget_id: u64, visible: bool) {
        self.set_widget_visible_impl(widget_id, visible)
    }
    fn is_widget_visible(&self, widget_id: u64) -> bool {
        self.is_widget_visible_impl(widget_id)
    }
    fn set_widget_value(&self, widget_id: u64, value: f64) -> bool {
        self.set_widget_value_impl(widget_id, value)
    }
    fn widget_value(&self, widget_id: u64) -> Option<f64> {
        self.widget_value_impl(widget_id)
    }
    fn set_widget_range(&self, widget_id: u64, min: f64, max: f64) -> bool {
        self.set_widget_range_impl(widget_id, min, max)
    }
    fn widget_range(&self, widget_id: u64) -> Option<(f64, f64)> {
        self.widget_range_impl(widget_id)
    }
    fn set_widget_selected_index(&self, widget_id: u64, index: Option<usize>) -> bool {
        self.set_widget_selected_index_impl(widget_id, index)
    }
    fn widget_selected_index(&self, widget_id: u64) -> Option<usize> {
        self.widget_selected_index_impl(widget_id)
    }
    fn set_widget_checked(&self, widget_id: u64, checked: bool) -> bool {
        self.set_widget_checked_impl(widget_id, checked)
    }
    fn is_widget_checked(&self, widget_id: u64) -> Option<bool> {
        self.is_widget_checked_impl(widget_id)
    }
    fn set_widget_step(&self, widget_id: u64, step: f64) -> bool {
        self.set_widget_step_impl(widget_id, step)
    }
    fn widget_step(&self, widget_id: u64) -> Option<f64> {
        self.widget_step_impl(widget_id)
    }
    fn set_widget_indeterminate(&self, widget_id: u64, indeterminate: bool) -> bool {
        self.set_widget_indeterminate_impl(widget_id, indeterminate)
    }
    fn is_widget_indeterminate(&self, widget_id: u64) -> Option<bool> {
        self.is_widget_indeterminate_impl(widget_id)
    }
    fn set_widget_read_only(&self, widget_id: u64, read_only: bool) -> bool {
        self.set_widget_read_only_impl(widget_id, read_only)
    }
    fn is_widget_read_only(&self, widget_id: u64) -> Option<bool> {
        self.is_widget_read_only_impl(widget_id)
    }
    fn set_widget_max_length(&self, widget_id: u64, max_length: u32) -> bool {
        self.set_widget_max_length_impl(widget_id, max_length)
    }
    fn widget_max_length(&self, widget_id: u64) -> Option<u32> {
        self.widget_max_length_impl(widget_id)
    }
    fn set_window_state(
        &self,
        widget_id: u64,
        flag: crate::platform::WindowStateFlag,
        on: bool,
    ) -> bool {
        self.set_window_state_impl(widget_id, flag, on)
    }
    fn is_window_in_state(
        &self,
        widget_id: u64,
        flag: crate::platform::WindowStateFlag,
    ) -> Option<bool> {
        self.is_window_in_state_impl(widget_id, flag)
    }
    fn set_window_min_size(&self, widget_id: u64, width: u32, height: u32) -> bool {
        self.set_window_min_size_impl(widget_id, width, height)
    }
    fn window_min_size(&self, widget_id: u64) -> Option<(u32, u32)> {
        self.window_min_size_impl(widget_id)
    }
    fn set_window_icon(&self, widget_id: u64, path: &str) -> bool {
        self.set_window_icon_impl(widget_id, path)
    }
    fn window_icon(&self, widget_id: u64) -> Option<String> {
        self.window_icon_impl(widget_id)
    }
    fn set_widget_selection(&self, widget_id: u64, start: u32, end: u32) -> bool {
        self.set_widget_selection_impl(widget_id, start, end)
    }
    fn widget_selection(&self, widget_id: u64) -> Option<(u32, u32)> {
        self.widget_selection_impl(widget_id)
    }
    fn set_widget_placeholder(&self, widget_id: u64, text: &str) -> bool {
        self.set_widget_placeholder_impl(widget_id, text)
    }
    fn widget_placeholder(&self, widget_id: u64) -> Option<String> {
        self.widget_placeholder_impl(widget_id)
    }
    fn set_widget_echo_mode(&self, widget_id: u64, mode: crate::platform::EchoMode) -> bool {
        self.set_widget_echo_mode_impl(widget_id, mode)
    }
    fn widget_echo_mode(&self, widget_id: u64) -> Option<crate::platform::EchoMode> {
        self.widget_echo_mode_impl(widget_id)
    }
    fn set_slider_orientation(
        &self,
        widget_id: u64,
        orientation: crate::core::Orientation,
    ) -> bool {
        self.set_slider_orientation_impl(widget_id, orientation)
    }
    fn slider_orientation(&self, widget_id: u64) -> Option<crate::core::Orientation> {
        self.slider_orientation_impl(widget_id)
    }
    fn set_widget_tristate(&self, widget_id: u64, enabled: bool) -> bool {
        self.set_widget_tristate_impl(widget_id, enabled)
    }
    fn is_widget_tristate(&self, widget_id: u64) -> Option<bool> {
        self.is_widget_tristate_impl(widget_id)
    }
    fn set_widget_group(&self, widget_id: u64, group: &str) -> bool {
        self.set_widget_group_impl(widget_id, group)
    }
    fn widget_group(&self, widget_id: u64) -> Option<String> {
        self.widget_group_impl(widget_id)
    }
    fn set_widget_scroll_position(&self, widget_id: u64, x: i32, y: i32) -> bool {
        self.set_widget_scroll_position_impl(widget_id, x, y)
    }
    fn widget_scroll_position(&self, widget_id: u64) -> Option<(i32, i32)> {
        self.widget_scroll_position_impl(widget_id)
    }
    fn set_widget_ime_enabled(&self, widget_id: u64, enabled: bool) -> bool {
        self.set_widget_ime_enabled_impl(widget_id, enabled)
    }
    fn is_widget_ime_enabled(&self, widget_id: u64) -> bool {
        self.is_widget_ime_enabled_impl(widget_id)
    }
    fn set_widget_accessibility_name(&self, widget_id: u64, name: &str) -> bool {
        self.set_widget_accessibility_name_impl(widget_id, name)
    }
    fn get_widget_accessibility_name(&self, widget_id: u64) -> String {
        self.get_widget_accessibility_name_impl(widget_id)
    }
    fn set_clipboard_text(&self, text: &str) -> bool {
        self.set_clipboard_text_impl(text)
    }
    fn get_clipboard_text(&self) -> String {
        self.get_clipboard_text_impl()
    }
    fn begin_drag(&self, source_widget_id: u64, mime: &str, payload: &[u8]) -> bool {
        self.begin_drag_impl(source_widget_id, mime, payload)
    }
    fn poll_drop_event(&self) -> Option<DropEvent> {
        self.poll_drop_event_impl()
    }
    fn inject_drop_event(&self, event: DropEvent) -> bool {
        self.inject_drop_event_impl(event)
    }
    fn create_message_box(
        &self,
        parent: u64,
        title: &str,
        text: &str,
        x: i32,
        y: i32,
        width: u32,
        height: u32,
    ) -> u64 {
        self.create_message_box_impl(parent, title, text, x, y, width, height)
    }
    fn create_file_dialog(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_file_dialog_impl(parent, x, y, width, height)
    }
    fn create_color_dialog(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_color_dialog_impl(parent, x, y, width, height)
    }
    fn create_font_dialog(&self, parent: u64, x: i32, y: i32, width: u32, height: u32) -> u64 {
        self.create_font_dialog_impl(parent, x, y, width, height)
    }

    #[cfg(target_os = "linux")]
    fn ime_bridge(&self) -> Option<&dyn crate::platform::ime::ImeBridge> {
        Some(&self.ime_bridge)
    }

    #[cfg(target_os = "linux")]
    fn accessibility_bridge(&self) -> Option<&dyn AccessibilityBridge> {
        static BRIDGE: OnceLock<LinuxAccessibilityBridge> = OnceLock::new();
        Some(BRIDGE.get_or_init(LinuxAccessibilityBridge::new))
    }
}