ranma 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,81 @@
1
+ use std::cell::RefCell;
2
+ use std::collections::HashMap;
3
+ use magnus::{gc, prelude::*, Ruby, RHash, Value};
4
+ use tao::window::{Window, WindowId};
5
+
6
+ struct WindowData {
7
+ tao_window: Window,
8
+ event_handler: Option<Value>,
9
+ }
10
+
11
+ thread_local! {
12
+ static WINDOWS: RefCell<HashMap<WindowId, WindowData>> = RefCell::new(HashMap::new());
13
+ }
14
+
15
+ pub fn register(id: WindowId, window: Window) {
16
+ WINDOWS.with(|windows| {
17
+ windows.borrow_mut().insert(
18
+ id,
19
+ WindowData {
20
+ tao_window: window,
21
+ event_handler: None,
22
+ },
23
+ );
24
+ });
25
+ }
26
+
27
+ pub fn with_window<F, R>(id: &WindowId, f: F) -> Option<R>
28
+ where
29
+ F: FnOnce(&Window) -> R,
30
+ {
31
+ WINDOWS.with(|windows| {
32
+ let windows = windows.borrow();
33
+ windows.get(id).map(|data| f(&data.tao_window))
34
+ })
35
+ }
36
+
37
+ pub fn set_event_handler(id: &WindowId, handler: Value) {
38
+ // Protect the handler from GC — it must survive across event loop iterations.
39
+ gc::register_mark_object(handler);
40
+ WINDOWS.with(|windows| {
41
+ if let Some(data) = windows.borrow_mut().get_mut(id) {
42
+ data.event_handler = Some(handler);
43
+ }
44
+ });
45
+ }
46
+
47
+ pub fn dispatch_event(_ruby: &Ruby, id: &WindowId, event_hash: RHash) {
48
+ WINDOWS.with(|windows| {
49
+ let windows = windows.borrow();
50
+ if let Some(data) = windows.get(id) {
51
+ if let Some(ref handler) = data.event_handler {
52
+ let result: Result<Value, _> = handler.funcall("call", (event_hash,));
53
+ if let Err(e) = result {
54
+ eprintln!("Ranma: Error in window event handler: {}", e);
55
+ }
56
+ }
57
+ }
58
+ });
59
+ }
60
+
61
+ pub fn remove(id: &WindowId) {
62
+ WINDOWS.with(|windows| {
63
+ windows.borrow_mut().remove(id);
64
+ });
65
+ }
66
+
67
+ pub fn request_redraw_all() {
68
+ WINDOWS.with(|windows| {
69
+ let windows = windows.borrow();
70
+ for data in windows.values() {
71
+ data.tao_window.request_redraw();
72
+ }
73
+ });
74
+ }
75
+
76
+
77
+ pub fn clear_all() {
78
+ WINDOWS.with(|windows| {
79
+ windows.borrow_mut().clear();
80
+ });
81
+ }
@@ -0,0 +1,3 @@
1
+ module Ranma
2
+ VERSION = "0.1.0"
3
+ end
data/lib/ranma.rb ADDED
@@ -0,0 +1,61 @@
1
+ require_relative "ranma/version"
2
+ require_relative "ranma/ranma"
3
+
4
+ module Ranma
5
+ class << self
6
+ alias_method :_run, :run
7
+
8
+ def run(&block)
9
+ _run(block)
10
+ end
11
+ end
12
+
13
+ class App
14
+ class << self
15
+ alias_method :_start, :start
16
+ alias_method :_on_menu_event, :on_menu_event
17
+ alias_method :_on_tray_event, :on_tray_event
18
+
19
+ def start(&block)
20
+ _start(block)
21
+ end
22
+
23
+ def on_menu_event(&block)
24
+ _on_menu_event(block)
25
+ end
26
+
27
+ def on_tray_event(&block)
28
+ _on_tray_event(block)
29
+ end
30
+ end
31
+ end
32
+
33
+ class AppWindow
34
+ alias_method :_on_event, :on_event
35
+
36
+ def on_event(&block)
37
+ _on_event(block)
38
+ end
39
+ end
40
+
41
+ class WebView
42
+ alias_method :_on_ipc_message, :on_ipc_message
43
+ alias_method :_on_navigation, :on_navigation
44
+
45
+ def on_ipc_message(&block)
46
+ _on_ipc_message(block)
47
+ end
48
+
49
+ def on_navigation(&block)
50
+ _on_navigation(block)
51
+ end
52
+ end
53
+
54
+ class HotKey
55
+ alias_method :_register, :register
56
+
57
+ def register(&block)
58
+ _register(block)
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ranma
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yasushi Itoh
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rb_sys
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ description: 'ranma wraps a suite of Rust crates: tao (windowing and event loop),
27
+ wry (WebView), Vello+wgpu (GPU 2D graphics), muda (native menus), tray-icon (system
28
+ tray), arboard (clipboard), global-hotkey, and dark-light (theme detection).'
29
+ executables: []
30
+ extensions:
31
+ - ext/ranma/extconf.rb
32
+ extra_rdoc_files: []
33
+ files:
34
+ - Cargo.lock
35
+ - Cargo.toml
36
+ - LICENSE
37
+ - README.md
38
+ - ext/ranma/Cargo.toml
39
+ - ext/ranma/extconf.rb
40
+ - ext/ranma/src/app.rs
41
+ - ext/ranma/src/blit.wgsl
42
+ - ext/ranma/src/clipboard.rs
43
+ - ext/ranma/src/dpi.rs
44
+ - ext/ranma/src/event_loop.rs
45
+ - ext/ranma/src/events.rs
46
+ - ext/ranma/src/hotkey.rs
47
+ - ext/ranma/src/ime.rs
48
+ - ext/ranma/src/lib.rs
49
+ - ext/ranma/src/menu.rs
50
+ - ext/ranma/src/monitor.rs
51
+ - ext/ranma/src/painter.rs
52
+ - ext/ranma/src/proxy.rs
53
+ - ext/ranma/src/surface.rs
54
+ - ext/ranma/src/theme.rs
55
+ - ext/ranma/src/tray.rs
56
+ - ext/ranma/src/webview.rs
57
+ - ext/ranma/src/window.rs
58
+ - ext/ranma/src/window_store.rs
59
+ - lib/ranma.rb
60
+ - lib/ranma/version.rb
61
+ homepage: https://github.com/i2y/ranma
62
+ licenses:
63
+ - MIT
64
+ metadata:
65
+ source_code_uri: https://github.com/i2y/ranma
66
+ bug_tracker_uri: https://github.com/i2y/ranma/issues
67
+ changelog_uri: https://github.com/i2y/ranma/releases
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 4.0.3
83
+ specification_version: 4
84
+ summary: Ruby bindings for native windowing, GPU 2D rendering, and WebView — powered
85
+ by Rust
86
+ test_files: []