rustimal 0.8.0

A minimal, GPU-rendered terminal for Windows that runs Git Bash, with animated split panes and a glass look
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
//! The mouse: links under it, clicks on the title bar, reports to programs that ask.

use super::*;
use winit::dpi::PhysicalPosition;

/// How a click is made: Ctrl shows the thing in Explorer, Alt runs it, Shift shows it inside the
/// pane. With none of them a click does what is handiest.
pub(super) fn click_mode(mods: ModifiersState) -> ClickMode {
    if mods.control_key() {
        ClickMode::Explorer
    } else if mods.alt_key() {
        ClickMode::Run
    } else if mods.shift_key() {
        ClickMode::Embed
    } else {
        ClickMode::Open
    }
}

impl App {
    pub(super) fn hit_test(&self, x: f32, y: f32) -> Hit {
        let Some(st) = self.state.as_ref() else { return Hit::None };
        let size = st.window.inner_size();
        let (w, h) = (size.width as f32, size.height as f32);
        if !st.window.is_maximized() {
            let e = (5.0 * st.scale).round();
            let c = e * 2.5;
            let (l, r, t, b) = (x < e, x >= w - e, y < e, y >= h - e);
            let (lc, rc, tc, bc) = (x < c, x >= w - c, y < c, y >= h - c);
            let dir = match () {
                _ if (t && lc) || (l && tc) => Some(ResizeDirection::NorthWest),
                _ if (t && rc) || (r && tc) => Some(ResizeDirection::NorthEast),
                _ if (b && lc) || (l && bc) => Some(ResizeDirection::SouthWest),
                _ if (b && rc) || (r && bc) => Some(ResizeDirection::SouthEast),
                _ if t => Some(ResizeDirection::North),
                _ if b => Some(ResizeDirection::South),
                _ if l => Some(ResizeDirection::West),
                _ if r => Some(ResizeDirection::East),
                _ => None,
            };
            if let Some(d) = dir {
                return Hit::Edge(d);
            }
        }
        if y < titlebar_height(st.scale) {
            for (hit, r) in title_buttons(st.scale, w) {
                if r.contains(x, y) {
                    return hit;
                }
            }
            return Hit::Title;
        }
        Hit::None
    }

    /// Find the link under the mouse so it can be underlined and clicked. Plain hover works
    /// unless `links_need_ctrl` is set; Ctrl also works in programs that take the mouse.
    pub(super) fn update_link(&mut self, force: bool) {
        let Some(st) = self.state.as_ref() else { return };
        let (x, y) = st.mouse;
        let ctrl = st.mods.control_key();
        let mode = click_mode(st.mods);
        let allowed = (mode != ClickMode::Open || !self.config.links_need_ctrl)
            && st.picker.is_none()
            && st.selecting.is_none()
            && st.mouse_reporting.is_none()
            && self.hit_test(x, y) == Hit::None;
        let cell = if allowed {
            self.pane_at(x, y)
                .filter(|&id| !self.chat_shows(id) && !self.review_shows(id))
                .and_then(|id| self.grid_point(id, x, y).map(|(point, ..)| (id, point)))
        } else {
            None
        };
        let probe = cell.map(|(id, point)| (id, point.line.0, point.column.0, mode));
        if !force && probe == st.link_probe {
            return;
        }
        let found = cell.and_then(|(id, point)| {
            let p = st.panes.iter().find(|p| p.id == id)?;
            let term = p.term.lock();
            // Programs like vim and htop get plain clicks; Ctrl takes them back.
            if !ctrl && term.mode().intersects(TermMode::MOUSE_MODE) {
                return None;
            }
            links::find(&term, point, p.cwd.as_deref()).map(|l| (id, l))
        });
        let Some(st) = self.state.as_mut() else { return };
        st.link_probe = probe;
        if st.hover_link == found {
            return;
        }
        for p in st.panes.iter_mut() {
            p.link = None;
        }
        if let Some((id, l)) = &found
            && let Some(p) = st.panes.iter_mut().find(|p| p.id == *id)
        {
            p.link = Some((l.line, l.start, l.end));
        }
        if found.is_some() {
            st.window.set_cursor(CursorIcon::Pointer);
        } else if st.hover == Hit::None {
            st.window.set_cursor(CursorIcon::Text);
        }
        st.hover_link = found;
        st.window.request_redraw();
    }

    /// A plain click on a link. A listing entry types a command into the shell: `cd` into a
    /// folder (then `ls`), `cat` a readable text file. Anything else opens as usual.
    pub(super) fn activate_link(&mut self, id: PaneId, target: &Target) {
        if let Target::Entry { path, name } = target
            && let Some(st) = self.state.as_mut()
            && let Some(p) = st.panes.iter_mut().find(|p| p.id == id)
            && p.can_type()
            && let Some(cmd) = links::entry_command(path, name)
        {
            p.term.lock().scroll_display(Scroll::Bottom);
            p.start_typing(cmd, Some(target.clone()));
            st.window.request_redraw();
            return;
        }
        self.open_target(id, target);
    }

    /// A click with Ctrl, Alt or Shift on a link. What is typed into the shell goes through
    /// the same way as a plain click's command; with the shell busy, or nothing to type, the
    /// thing is simply opened.
    ///
    /// - Ctrl: show it in Explorer.
    /// - Alt: run it: a program, a folder entered, a text file printed.
    /// - Shift: show it inside the pane: a program with `embed`, a folder or file in VS
    ///   Code, an address in the browser.
    pub(super) fn activate_link_as(&mut self, id: PaneId, target: &Target, mode: ClickMode) {
        let path = links::path_of(target).map(std::path::Path::to_path_buf);
        let name = match target {
            Target::Entry { name, .. } => Some(name.clone()),
            _ => path.as_ref().and_then(|p| p.file_name()).map(|n| n.to_string_lossy().into_owned()),
        };
        let command = match (mode, &path, target) {
            (ClickMode::Explorer, Some(path), _) => {
                links::show_in_explorer(path);
                return;
            }
            (ClickMode::Run, Some(path), Target::Entry { .. } | Target::Path(_)) => {
                links::run_command(path, name.as_deref().unwrap_or_default())
            }
            (ClickMode::Embed, Some(path), Target::Entry { .. } | Target::Path(_)) => links::embed_command(path),
            (ClickMode::Embed, _, Target::Url(url)) => Some(links::embed_url_command(url)),
            _ => None,
        };
        if let Some(command) = command
            && let Some(st) = self.state.as_mut()
            && let Some(p) = st.panes.iter_mut().find(|p| p.id == id)
            && p.can_type()
        {
            p.term.lock().scroll_display(Scroll::Bottom);
            p.start_typing(command, Some(target.clone()));
            st.window.request_redraw();
            return;
        }
        // Nothing to type, or the shell is busy: open it as a link opens.
        match target {
            Target::Entry { .. } => links::open(target, &self.config.editor),
            target => self.open_target(id, target),
        }
    }

    /// A file was dropped on the window: type its path at the cursor, like a paste.
    pub(super) fn drop_path(&mut self, path: &std::path::Path) {
        let Some(st) = self.state.as_mut() else { return };
        let (x, y) = st.mouse;
        let id = st.panes.iter().find(|p| p.target.contains(x, y)).map_or(st.focused, |p| p.id);
        if self.review_drop(id, path) {
            return;
        }
        let Some(st) = self.state.as_mut() else { return };
        if let Some(chat) = st.panes.iter_mut().find(|p| p.id == id).and_then(|p| p.chat.as_mut()).filter(|c| !c.hidden)
        {
            chat.insert(&format!("\"{}\" ", path.display()));
            st.window.request_redraw();
            return;
        }
        let Some(p) = st.panes.iter().find(|p| p.id == id) else { return };
        // Claude takes Windows paths; shells want the Git Bash form.
        let word = if p.claude {
            let s = path.to_string_lossy().into_owned();
            if s.contains(' ') { format!("\"{s}\"") } else { s }
        } else {
            links::shell_word(&links::msys_path(path))
        };
        let mut text = format!("{word} ");
        if p.term.lock().mode().contains(TermMode::BRACKETED_PASTE) {
            text = format!("\x1b[200~{text}\x1b[201~");
        }
        p.term.lock().scroll_display(Scroll::Bottom);
        p.write(text.into_bytes());
        st.window.request_redraw();
    }

    /// Title bar and window-edge clicks. Returns true if consumed.
    pub(super) fn chrome_click(&mut self, event_loop: &ActiveEventLoop, state: ElementState) -> bool {
        let Some(st) = self.state.as_mut() else { return false };
        let hover = st.hover;
        match state {
            ElementState::Pressed => match hover {
                Hit::Edge(dir) => {
                    let _ = st.window.drag_resize_window(dir);
                    true
                }
                Hit::Title => {
                    let now = Instant::now();
                    let double = st.last_title_click.is_some_and(|t| now - t < Duration::from_millis(400));
                    st.last_title_click = Some(now);
                    if double {
                        st.window.set_maximized(!st.window.is_maximized());
                        st.last_title_click = None;
                    } else {
                        let _ = st.window.drag_window();
                    }
                    true
                }
                Hit::Min | Hit::Max | Hit::Close => {
                    st.pressed = hover;
                    st.window.request_redraw();
                    true
                }
                Hit::None => false,
            },
            ElementState::Released => {
                let pressed = std::mem::replace(&mut st.pressed, Hit::None);
                if pressed == Hit::None {
                    return false;
                }
                st.window.request_redraw();
                if pressed == hover {
                    match pressed {
                        Hit::Min => st.window.set_minimized(true),
                        Hit::Max => st.window.set_maximized(!st.window.is_maximized()),
                        Hit::Close => event_loop.exit(),
                        _ => {}
                    }
                }
                true
            }
        }
    }

    pub(super) fn mouse_report(&self, id: PaneId, button: u8, pressed: bool, motion: bool) -> bool {
        let Some(st) = self.state.as_ref() else { return false };
        let Some(p) = st.panes.iter().find(|p| p.id == id) else { return false };
        let mode = *p.term.lock().mode();
        if !mode.intersects(TermMode::MOUSE_MODE) || st.mods.shift_key() {
            return false;
        }
        if motion && !mode.intersects(TermMode::MOUSE_DRAG | TermMode::MOUSE_MOTION) {
            return true;
        }
        let Some((_, _, col, row)) = self.grid_point(id, st.mouse.0, st.mouse.1) else { return false };
        let m = st.mods;
        let b = button
            + if motion { 32 } else { 0 }
            + if m.alt_key() { 8 } else { 0 }
            + if m.control_key() { 16 } else { 0 };
        let bytes = if mode.contains(TermMode::SGR_MOUSE) {
            format!("\x1b[<{};{};{}{}", b, col + 1, row + 1, if pressed { 'M' } else { 'm' }).into_bytes()
        } else {
            let b = if pressed { b } else { 3 };
            let enc = |v: usize| (32 + v + 1).min(255) as u8;
            vec![0x1b, b'[', b'M', 32 + b, enc(col), enc(row)]
        };
        p.write(bytes);
        true
    }

    /// The window gained or lost the keyboard focus.
    pub(super) fn on_focus(&mut self, focused: bool) {
        // A T3 Code view taking the keyboard leaves this window in front.
        let focused = self.web_focus_changed(focused);
        let st = self.state.as_mut().unwrap();
        st.window_focused = focused;
        let id = st.focused;
        if let Some(p) = st.panes.iter().find(|p| p.id == id) {
            let mut term = p.term.lock();
            term.is_focused = focused;
            let report = term.mode().contains(TermMode::FOCUS_IN_OUT);
            drop(term);
            if report {
                p.write(if focused { b"\x1b[I".to_vec() } else { b"\x1b[O".to_vec() });
            }
        }
        st.blink_epoch = Instant::now();
        if focused {
            st.notice = None;
        }
        st.window.request_redraw();
    }

    /// The mouse moved over the window.
    pub(super) fn on_cursor_moved(&mut self, position: PhysicalPosition<f64>) {
        let (x, y) = (position.x as f32, position.y as f32);
        self.state.as_mut().unwrap().mouse = (x, y);
        if self.overlay_hover() {
            return;
        }
        let busy = {
            let st = self.state.as_ref().unwrap();
            st.selecting.is_some() || st.cmd_drag.is_some() || st.mouse_reporting.is_some()
        };
        if !busy {
            let hit = self.hit_test(x, y);
            let st = self.state.as_mut().unwrap();
            if hit != st.hover {
                st.hover = hit;
                st.window.set_cursor(match hit {
                    Hit::Edge(ResizeDirection::East | ResizeDirection::West) => CursorIcon::EwResize,
                    Hit::Edge(ResizeDirection::North | ResizeDirection::South) => CursorIcon::NsResize,
                    Hit::Edge(ResizeDirection::NorthEast | ResizeDirection::SouthWest) => CursorIcon::NeswResize,
                    Hit::Edge(_) => CursorIcon::NwseResize,
                    Hit::None => CursorIcon::Text,
                    _ => CursorIcon::Default,
                });
                st.window.request_redraw();
            }
        }
        if self.review_hover() {
            return;
        }
        self.picker_mouse(None, 0.0);
        let st = self.state.as_ref().unwrap();
        if let Some(id) = st.mouse_reporting {
            self.mouse_report(id, 0, true, true);
        } else if let Some(id) = st.cmd_drag {
            if let Some((point, side, _, _)) = self.grid_point(id, x, y) {
                let st = self.state.as_mut().unwrap();
                if let Some(p) = st.panes.iter_mut().find(|p| p.id == id) {
                    p.drag_to(point.column.0, side == Side::Right);
                }
                st.blink_epoch = Instant::now();
                st.window.request_redraw();
            }
        } else if let Some(id) = st.selecting
            && let Some((point, side, _, _)) = self.grid_point(id, x, y)
        {
            let st = self.state.as_ref().unwrap();
            if let Some(p) = st.panes.iter().find(|p| p.id == id)
                && let Some(sel) = p.term.lock().selection.as_mut()
            {
                sel.update(point, side);
            }
            st.window.request_redraw();
        }
        self.update_link(false);
    }

    /// A mouse button went down or up.
    pub(super) fn on_mouse_button(&mut self, event_loop: &ActiveEventLoop, state: ElementState, button: MouseButton) {
        if self.overlay_click(event_loop, button, state) {
            return;
        }
        let (x, y) = self.state.as_ref().unwrap().mouse;
        if button == MouseButton::Left && self.chrome_click(event_loop, state) {
            return;
        }
        if self.review_click(button, state) {
            return;
        }
        if self.chat_click(button, state) {
            return;
        }
        if state == ElementState::Pressed && self.picker_mouse(Some(button), 0.0) {
            return;
        }
        // Letting go outside every pane still ends a drag that began on a command line.
        if button == MouseButton::Left && state == ElementState::Released {
            let st = self.state.as_mut().unwrap();
            if let Some(cid) = st.cmd_drag.take() {
                if let Some(p) = st.panes.iter_mut().find(|p| p.id == cid) {
                    p.drag = None;
                }
                st.window.request_redraw();
                return;
            }
        }
        let Some(id) = self.pane_at(x, y) else { return };
        match (button, state) {
            (MouseButton::Left, ElementState::Pressed) => {
                let st = self.state.as_mut().unwrap();
                let was_focused = st.focused == id;
                st.link_press = None;
                if let Some(p) = st.panes.iter_mut().find(|p| p.id == id) {
                    p.kb_sel = None;
                }
                if !was_focused {
                    let prev = st.focused;
                    st.focused = id;
                    notify_focus(st, prev);
                }
                // Ctrl+click on a link opens it right away. A plain click opens it on
                // release, if the mouse has not moved (so dragging still selects), and
                // not when the click only focused the pane.
                self.update_link(true);
                let st = self.state.as_mut().unwrap();
                if let Some((_, link)) = st.hover_link.clone() {
                    // Ctrl, Alt and Shift pick a way to deal with it right away.
                    let mode = click_mode(st.mods);
                    if mode != ClickMode::Open {
                        self.activate_link_as(id, &link.target, mode);
                        return;
                    }
                    if was_focused {
                        st.link_press = Some((id, (x, y), link));
                    }
                }
                if self.mouse_report(id, 0, true, false) {
                    self.state.as_mut().unwrap().mouse_reporting = Some(id);
                    return;
                }
                let st = self.state.as_mut().unwrap();
                let now = Instant::now();
                let count = match st.last_click {
                    Some((t, n, (lx, ly)))
                        if now - t < Duration::from_millis(400) && (lx - x).abs() < 4.0 && (ly - y).abs() < 4.0 =>
                    {
                        n % 3 + 1
                    }
                    _ => 1,
                };
                st.last_click = Some((now, count, (x, y)));
                // A press on the command line puts the cursor there, and dragging moves
                // it without selecting. After a double click the drag selects what the
                // cursor passes. A triple click selects the line.
                if count <= 2
                    && self.state.as_ref().unwrap().link_press.is_none()
                    && !self.state.as_ref().unwrap().mods.control_key()
                    && let Some((point, side, _, _)) = self.grid_point(id, x, y)
                {
                    let st = self.state.as_mut().unwrap();
                    let used =
                        st.panes.iter_mut().find(|p| p.id == id).is_some_and(|p| {
                            p.press_cursor(point.line.0, point.column.0, side == Side::Right, count == 2)
                        });
                    if used {
                        st.cmd_drag = Some(id);
                        st.blink_epoch = Instant::now();
                        st.window.request_redraw();
                        return;
                    }
                }
                if let Some((point, side, _, _)) = self.grid_point(id, x, y) {
                    let ty = match count {
                        2 => SelectionType::Semantic,
                        3 => SelectionType::Lines,
                        _ => SelectionType::Simple,
                    };
                    let st = self.state.as_mut().unwrap();
                    if let Some(p) = st.panes.iter().find(|p| p.id == id) {
                        p.term.lock().selection = Some(Selection::new(ty, point, side));
                    }
                    st.selecting = Some(id);
                    st.window.request_redraw();
                }
            }
            (MouseButton::Left, ElementState::Released) => {
                let st = self.state.as_mut().unwrap();
                if let Some(rid) = st.mouse_reporting.take() {
                    self.mouse_report(rid, 0, false, false);
                    return;
                }
                if let Some((pid, (px, py), link)) = st.link_press.take()
                    && pid == id
                    && (px - x).abs() < 4.0
                    && (py - y).abs() < 4.0
                    && st.last_click.is_some_and(|(_, n, _)| n == 1)
                {
                    st.selecting = None;
                    if let Some(p) = st.panes.iter().find(|p| p.id == id) {
                        p.term.lock().selection = None;
                    }
                    st.window.request_redraw();
                    self.activate_link(id, &link.target);
                    return;
                }
                let st = self.state.as_mut().unwrap();
                if st.selecting.take().is_some() && self.config.copy_on_select {
                    self.copy_selection(false);
                }
            }
            (MouseButton::Right, ElementState::Pressed) => {
                // Right-click on a link: a menu of what can be done with it.
                self.update_link(true);
                if let Some((link_pane, link)) = self.state.as_ref().unwrap().hover_link.clone() {
                    self.open_link_menu(link_pane, &link);
                    return;
                }
                if self.mouse_report(id, 2, true, false) {
                    return;
                }
                if !self.copy_selection(true) {
                    self.paste();
                }
                self.state.as_ref().unwrap().window.request_redraw();
            }
            (MouseButton::Right, ElementState::Released) => {
                self.mouse_report(id, 2, false, false);
            }
            (MouseButton::Middle, ElementState::Pressed) if !self.mouse_report(id, 1, true, false) => {
                self.paste();
            }
            _ => {}
        }
    }

    /// The wheel turned.
    pub(super) fn on_mouse_wheel(&mut self, delta: MouseScrollDelta) {
        let wheel = match delta {
            MouseScrollDelta::LineDelta(_, dy) => dy,
            MouseScrollDelta::PixelDelta(pos) => pos.y as f32,
        };
        if self.overlay_wheel(wheel) {
            return;
        }
        if self.review_wheel(match delta {
            MouseScrollDelta::LineDelta(_, dy) => dy,
            MouseScrollDelta::PixelDelta(pos) => pos.y as f32 / 40.0,
        }) {
            return;
        }
        if self.chat_wheel(match delta {
            MouseScrollDelta::LineDelta(_, dy) => dy,
            MouseScrollDelta::PixelDelta(pos) => pos.y as f32 / 40.0,
        }) {
            return;
        }
        if self.picker_mouse(None, wheel) {
            return;
        }
        let (x, y) = self.state.as_ref().unwrap().mouse;
        let Some(id) = self.pane_at(x, y) else { return };
        let st = self.state.as_mut().unwrap();
        let cell_h = st.glyphs.cell_h;
        let Some(p) = st.panes.iter_mut().find(|p| p.id == id) else { return };
        let lines = match delta {
            MouseScrollDelta::LineDelta(_, dy) => dy * 3.0,
            MouseScrollDelta::PixelDelta(pos) => pos.y as f32 / cell_h,
        };
        p.scroll_accum += lines;
        let whole = p.scroll_accum.trunc() as i32;
        if whole == 0 {
            return;
        }
        p.scroll_accum -= whole as f32;
        let mode = *p.term.lock().mode();
        if mode.intersects(TermMode::MOUSE_MODE) && !st.mods.shift_key() {
            let button = if whole > 0 { 64 } else { 65 };
            for _ in 0..whole.abs() {
                self.mouse_report(id, button, true, false);
            }
        } else if mode.contains(TermMode::ALT_SCREEN | TermMode::ALTERNATE_SCROLL) {
            let seq: &[u8] = match (whole > 0, mode.contains(TermMode::APP_CURSOR)) {
                (true, true) => b"\x1bOA",
                (true, false) => b"\x1b[A",
                (false, true) => b"\x1bOB",
                (false, false) => b"\x1b[B",
            };
            p.write(seq.repeat(whole.unsigned_abs() as usize));
        } else {
            p.term.lock().scroll_display(Scroll::Delta(whole));
            st.window.request_redraw();
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn ctrl_alt_and_shift_pick_the_way_a_click_is_handled() {
        assert_eq!(click_mode(ModifiersState::empty()), ClickMode::Open);
        assert_eq!(click_mode(ModifiersState::CONTROL), ClickMode::Explorer);
        assert_eq!(click_mode(ModifiersState::ALT), ClickMode::Run);
        assert_eq!(click_mode(ModifiersState::SHIFT), ClickMode::Embed);
        // Together, the first of Ctrl, Alt, Shift wins.
        assert_eq!(click_mode(ModifiersState::CONTROL | ModifiersState::SHIFT), ClickMode::Explorer);
        assert_eq!(click_mode(ModifiersState::ALT | ModifiersState::SHIFT), ClickMode::Run);
    }
}