diff --git a/components/launcher/gen/interface/chandra/desktop/plasmoid/stub.mbt b/components/launcher/gen/interface/chandra/desktop/plasmoid/stub.mbt index 4a82985..133337a 100644 --- a/components/launcher/gen/interface/chandra/desktop/plasmoid/stub.mbt +++ b/components/launcher/gen/interface/chandra/desktop/plasmoid/stub.mbt @@ -13,7 +13,7 @@ pub fn info() -> PlasmoidInfo { id: "org.chandra.launcher", name: "Application Launcher", preferred: { w: 150, h: 34 }, - min_width: 60, + min_width: 36, stretch: false, } } diff --git a/compositor/host/auth_draw.mbt b/compositor/host/auth_draw.mbt index ba68055..f8deb14 100644 --- a/compositor/host/auth_draw.mbt +++ b/compositor/host/auth_draw.mbt @@ -433,7 +433,8 @@ fn ChandraCompositor::auth_ops(self : ChandraCompositor) -> Array[@scene.DrawOp] // Place the card in the middle (shaking after a failure) with a soft shadow. let h = y let cx = (sw - w) / 2 + d.shake_offset(now) - let cyy = ((sh - h) / 2).max(8) + let avail_h = if self.osk_visible { sh - self.osk_height() } else { sh } + let cyy = ((avail_h - h) / 2).max(8) for k = 1; k <= 4; k = k + 1 { ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(cx - k * 2, cyy - k * 2 + 6, w + k * 4, h + k * 4), @scene.Rgba::new(0, 0, 0, 22), rad + 6 + k * 2)) } diff --git a/compositor/host/compositor.mbt b/compositor/host/compositor.mbt index 420880e..d21ab18 100644 --- a/compositor/host/compositor.mbt +++ b/compositor/host/compositor.mbt @@ -312,6 +312,20 @@ pub(all) struct ChandraCompositor { /// External windows from the host X11 WM (`--x11`), bridged into the dock/panel only. mut ext_windows : Array[ExternalWindow] mut ext_handler : ExternalWindowHandler? + /// Built-in on-screen keyboard (osk.mbt). + mut osk_enabled : Bool + mut osk_visible : Bool + mut osk_shift : Bool + mut osk_ctrl : Bool + mut osk_alt : Bool + mut osk_sym : Bool + mut osk_manual_hide : Bool + mut osk_manual_show : Bool + mut osk_popup_typing : Bool + mut osk_target : String + mut osk_pressed : Int? + mut osk_hover : Int? + mut osk_pointer_grab : Bool } ///| @@ -448,6 +462,19 @@ pub fn ChandraCompositor::new( kiosk: None, ext_windows: [], ext_handler: None, + osk_enabled: osk_default_enabled(), + osk_visible: false, + osk_shift: false, + osk_ctrl: false, + osk_alt: false, + osk_sym: false, + osk_manual_hide: false, + osk_manual_show: false, + osk_popup_typing: false, + osk_target: "", + osk_pressed: None, + osk_hover: None, + osk_pointer_grab: false, } // Client popups (menus) are placed to stay on screen: the server asks for the output's // rectangle relative to the parent's content origin when it applies constraint adjustment. @@ -459,18 +486,44 @@ pub fn ChandraCompositor::new( } ///| The part of a `w` x `h` output windows are laid out in. -fn work_area_for(w : Int, h : Int, theme : @scene.ThemeTokens, kiosk~ : Bool = false) -> @wm.Rect { +fn work_area_for( + w : Int, + h : Int, + theme : @scene.ThemeTokens, + kiosk~ : Bool = false, + bottom_extra~ : Int = 0, +) -> @wm.Rect { if kiosk { - // A locked kiosk has no panel and its windows are fullscreen: the whole output. - return { x: 0, y: 0, w, h } + // A locked kiosk has no panel and its windows are fullscreen: the whole output (above OSK). + let bh = h - bottom_extra + return { x: 0, y: 0, w, h: if bh > 1 { bh } else { 1 } } } + let excl_bottom = if bottom_extra > theme.panel_height { bottom_extra } else { theme.panel_height } @wm.compute_work_area( { x: 0, y: 0, w, h }, excl_top=frame_top(), // room for the server-side title bar drawn above each client - excl_bottom=theme.panel_height, + excl_bottom~, ) } +///| Recompute the window work area and shell popup clearance (e.g. when OSK opens/closes). +fn ChandraCompositor::recompute_work_area(self : ChandraCompositor) -> Unit { + let bottom_extra = if self.osk_visible { self.osk_height() } else { 0 } + self.work_area = work_area_for( + self.output_w, + self.output_h, + self.theme, + kiosk=self.kiosk_strict(), + bottom_extra~, + ) + self.shell.set_popup_bottom_inset(bottom_extra) + self.apply_actions(self.wm.fit_work_area(self.work_area)) + self.last_frame = None + self.last_sig = None + self.frame_changed = true + self.damage.mark_full() +} + ///| The output changed size (the nested window was resized, maximized or made fullscreen): /// lay the desktop out for the new size, so nothing is drawn past the edge and cropped away. pub fn ChandraCompositor::resize(self : ChandraCompositor, w : Int, h : Int) -> Unit { @@ -479,11 +532,13 @@ pub fn ChandraCompositor::resize(self : ChandraCompositor, w : Int, h : Int) -> } self.output_w = w self.output_h = h - self.work_area = work_area_for(w, h, self.theme, kiosk=self.kiosk_strict()) + let bottom_extra = if self.osk_visible { self.osk_height() } else { 0 } + self.work_area = work_area_for(w, h, self.theme, kiosk=self.kiosk_strict(), bottom_extra~) self.close_overlay() // its frozen frame is the old size self.stop_recording() self.server.set_output_size(w, h) self.shell.set_output(self.theme, w, h) + self.shell.set_popup_bottom_inset(bottom_extra) self.apply_actions(self.wm.fit_work_area(self.work_area)) self.last_frame = None self.last_sig = None @@ -901,6 +956,7 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit { self.session_tick() self.screenshot_tick() self.recording_tick() + self.osk_sync() } ///| True while something runs on a timer rather than on input or client messages (a recording, @@ -1143,6 +1199,7 @@ fn ChandraCompositor::build_scene( panel_ops.append(self.face_window_ops()) panel_ops.append(self.auth_ops()) panel_ops.append(self.auth_notice_ops()) + panel_ops.append(self.osk_ops()) self.frames_built = self.frames_built + 1 self.run_shell_actions() // The wallpaper (the first ops) is cached by the renderer; the desktop card after it changes. @@ -1749,7 +1806,14 @@ pub fn ChandraCompositor::sync_window_style(self : ChandraCompositor) -> Unit { window_style.val = style self.wm.titlebar_h = frame_top() self.wm.border_w = frame_side() - self.work_area = work_area_for(self.output_w, self.output_h, self.theme, kiosk=self.kiosk_strict()) + let bottom_extra = if self.osk_visible { self.osk_height() } else { 0 } + self.work_area = work_area_for( + self.output_w, + self.output_h, + self.theme, + kiosk=self.kiosk_strict(), + bottom_extra~, + ) self.apply_actions(self.wm.fit_work_area(self.work_area)) for _, win in self.windows { if win.csd { @@ -1875,7 +1939,6 @@ fn key_name(code : UInt, shift : Bool) -> String { (16U, "qwertyuiop"), (30U, "asdfghjkl"), (44U, "zxcvbnm"), - (2U, "1234567890"), ] for r in rows { let (first, chars) = r @@ -1888,30 +1951,53 @@ fn key_name(code : UInt, shift : Bool) -> String { } } } + if code >= 2U && code <= 11U { + let digits = "1234567890" + let shifted = "!@#$%^&*()" + let s = if shift { shifted } else { digits } + let c = Int::unsafe_to_char(s[(code - 2U).reinterpret_as_int()].to_int()) + return c.to_string() + } match code { 1U => "Escape" 14U => "Backspace" 28U => "Enter" 57U => " " - 12U => "-" + 12U => if shift { "_" } else { "-" } 13U => if shift { "+" } else { "=" } 15U => "Tab" + 26U => if shift { "{" } else { "[" } + 27U => if shift { "}" } else { "]" } + 39U => if shift { ":" } else { ";" } + 40U => if shift { "\"" } else { "'" } + 41U => if shift { "~" } else { "`" } + 43U => if shift { "|" } else { "\\" } + 51U => if shift { "<" } else { "," } + 52U => if shift { ">" } else { "." } + 53U => if shift { "?" } else { "/" } 103U => "ArrowUp" 108U => "ArrowDown" 105U => "ArrowLeft" 106U => "ArrowRight" - 52U => "." - 53U => "/" _ => "" } } -///| Route host input: shell (launcher) first, then the window under the pointer -/// / the keyboard-focused window. +///| Route host input: OSK first, then grabs, shell (launcher), and focused window. pub fn ChandraCompositor::handle_input( self : ChandraCompositor, ev : @nested.InputEvent, time_ms : UInt, +) -> Unit { + self.handle_input_inner(ev, time_ms) + self.osk_sync() +} + +///| +fn ChandraCompositor::handle_input_inner( + self : ChandraCompositor, + ev : @nested.InputEvent, + time_ms : UInt, ) -> Unit { self.note_activity(@sys.monotonic_ms()) match ev { @@ -1925,6 +2011,9 @@ pub fn ChandraCompositor::handle_input( } _ => () } + if self.osk_input(ev, time_ms) { + return + } // The password dialog takes all input while it is up; else the Face unlock window does. if self.grab_input(ev) { return @@ -2199,6 +2288,9 @@ pub fn ChandraCompositor::handle_input( self.super_solo = false if button != 273U && self.shell.pointer_down(xi, yi) { self.run_shell_actions() + if button == 272U { + self.osk_on_shell_click(xi, yi) + } return } match self.window_at(xi, yi) { @@ -2250,8 +2342,11 @@ pub fn ChandraCompositor::handle_input( return } match self.window_at(xi, yi) { - Some((wid, _)) => { + Some((wid, client)) => { self.activate_window(wid) + if button == 272U && client { + self.osk_on_window_click(wid) + } } None => () } @@ -2334,6 +2429,9 @@ pub fn ChandraCompositor::handle_input( ///| Cursor shape (wp_cursor_shape_v1 value) for the current pointer position: shell UI /// decides over the launcher; a client window decides inside its client area; otherwise default. pub fn ChandraCompositor::desired_cursor(self : ChandraCompositor) -> UInt { + if self.osk_hit_any(self.ptr_x.to_int(), self.ptr_y.to_int()) { + return 4U + } match self.auth { Some(ui) => return self.auth_cursor(ui) None => () diff --git a/compositor/host/control.mbt b/compositor/host/control.mbt index c0d1d28..c612214 100644 --- a/compositor/host/control.mbt +++ b/compositor/host/control.mbt @@ -212,6 +212,7 @@ pub fn ChandraCompositor::control_command(self : ChandraCompositor, line : Strin "kiosk [lock|unlock|status] kiosk mode (--kiosk): lock it down or unlock it for admin work", "launch ID start desktop app ID (e.g. org.kde.kwi) as the dock does; a failed start shows its notice", "windows each window: frame, layout, box, shadow, size limits; and what is under the pointer", + "screenshot [PATH] save a full-screen PNG directly (without opening the editor)", "auth-demo [MODE] show the password dialog with a pretend check (password \"demo\"); MODE: " + @polkit.demo_modes.join(", "), "auth-status the password dialog's agent: running, registered, or why not", @@ -329,6 +330,35 @@ pub fn ChandraCompositor::control_command(self : ChandraCompositor, line : Strin out.push("ok " + self.windows.length().to_string() + " windows") (out, true) } + "screenshot" => { + if words.length() > 2 { + return (["error usage: screenshot [PATH]"], false) + } + match self.capture_png() { + None => (["error could not capture screen"], false) + Some(png) => + if words.length() == 2 { + let path = words[1] + if @sys.write_file_bytes(path, png) == 0 { + (["ok " + path], true) + } else { + (["error could not write " + path], false) + } + } else { + let dir = if self.shot_dir.length() > 0 { + self.shot_dir + } else { + pictures_dir() + "/Screenshots" + } + let path = save_png(dir, png) + if path != "" { + (["ok " + path], true) + } else { + (["error could not save screenshot in " + dir], false) + } + } + } + } other => (["error unknown command '" + other + "' (try: help)"], false) } } diff --git a/compositor/host/emoji_picker.mbt b/compositor/host/emoji_picker.mbt index 4eee3b7..be8b5c8 100644 --- a/compositor/host/emoji_picker.mbt +++ b/compositor/host/emoji_picker.mbt @@ -181,7 +181,12 @@ fn ChandraCompositor::emoji_place(self : ChandraCompositor, ui : EmojiUi) -> Uni let (ox, oy) = win.surface_origin() x = ox + cx y = oy + cy + ch + 6 - if y + h > sh - self.theme.panel_height { + let bottom_edge = if self.osk_visible { + self.output_h - self.osk_height() + } else { + sh - self.theme.panel_height + } + if y + h > bottom_edge { y = oy + cy - h - 6 // no room under the caret: above it } } @@ -195,8 +200,9 @@ fn ChandraCompositor::emoji_place(self : ChandraCompositor, ui : EmojiUi) -> Uni } None => () } - x = x.min(sw - w - 8).max(8) - y = y.min(sh - h - 8).max(8) + x = x.min((sw - w - 8).max(8)).max(8) + let max_y = (if self.osk_visible { sh - self.osk_height() } else { sh }) - h - 8 + y = y.min(max_y.max(8)).max(8) ui.rect = @scene.Rect::new(x, y, w, h) } diff --git a/compositor/host/kiosk.mbt b/compositor/host/kiosk.mbt index 852d769..dfc5da7 100644 --- a/compositor/host/kiosk.mbt +++ b/compositor/host/kiosk.mbt @@ -177,7 +177,14 @@ fn ChandraCompositor::apply_kiosk_lock(self : ChandraCompositor) -> Unit { self.switcher_on = false } } - self.work_area = work_area_for(self.output_w, self.output_h, self.theme, kiosk=locked) + let bottom_extra = if self.osk_visible { self.osk_height() } else { 0 } + self.work_area = work_area_for( + self.output_w, + self.output_h, + self.theme, + kiosk=locked, + bottom_extra~, + ) if !locked { // Give the windows the kiosk made fullscreen back to the normal layout. let ids : Array[UInt64] = [] diff --git a/compositor/host/osk.mbt b/compositor/host/osk.mbt new file mode 100644 index 0000000..4364b4d --- /dev/null +++ b/compositor/host/osk.mbt @@ -0,0 +1,698 @@ +///| Built-in on-screen keyboard (OSK) for touch / handset sessions. +/// +/// Chandra does not expose external wlr-layer-shell / virtual-keyboard protocols, so a built-in +/// compositor OSK works uniformly across Wayland clients (wl_keyboard evdev codes + modifiers), +/// panel popups (Launcher search, Network password), the emoji picker, and the polkit dialog. +/// +/// Enablement: `CHANDRA_OSK=1|0` overrides; under `CHANDRA_TEST_CONFIG=1` it stays off unless +/// explicitly enabled; otherwise enabled when `/etc/machine-info` reports `CHASSIS=handset`. + +///| +priv enum OskAction { + OskKeyCode(UInt, Bool) // evdev keycode, implicit Shift + OskShift + OskCtrl + OskAlt + OskSym + OskHide +} + +///| +priv struct OskKey { + rect : @scene.Rect + label : String + action : OskAction + active : Bool + accent : Bool +} + +///| Default OSK enablement at compositor startup. +fn osk_default_enabled() -> Bool { + let env = @sys.getenv("CHANDRA_OSK").to_lower() + if env == "1" || env == "true" || env == "on" { + return true + } + if env == "0" || env == "false" || env == "off" { + return false + } + if @sys.getenv("CHANDRA_TEST_CONFIG") != "" { + return false + } + let info = @utf8.decode_lossy(@sys.read_file_bytes("/etc/machine-info")) + info.contains("CHASSIS=handset") +} + +///| Whether `app_id` belongs to a terminal emulator (terminals use direct keystrokes rather than +/// zwp_text_input_v3, so focusing one auto-opens the OSK). +fn osk_is_terminal_app(app_id : String) -> Bool { + let id = app_id.to_lower() + if id.length() == 0 { + return false + } + for name in [ + "foot", "kitty", "alacritty", "wezterm", "konsole", "ghostty", "xterm", "urxvt", "st", + "gnome-terminal", "terminal", + ] { + if id.contains(name) { + return true + } + } + false +} + +///| Enable or disable the on-screen keyboard at runtime (used in tests and toggles). +pub fn ChandraCompositor::set_osk_enabled(self : ChandraCompositor, enabled : Bool) -> Unit { + if self.osk_enabled == enabled { + return + } + self.osk_enabled = enabled + if !enabled { + self.osk_manual_hide = false + self.osk_manual_show = false + self.osk_popup_typing = false + self.osk_set_visible(false) + } else { + self.osk_sync() + } + self.damage.mark_full() +} + +///| Whether the on-screen keyboard is currently visible. +pub fn ChandraCompositor::osk_is_visible(self : ChandraCompositor) -> Bool { + self.osk_visible +} + +///| Center `(x, y)` of the visible OSK key matching `label` (useful for automated tests). +pub fn ChandraCompositor::osk_key_center(self : ChandraCompositor, label : String) -> (Int, Int)? { + if !self.osk_visible { + return None + } + for k in self.osk_keys() { + if k.label == label { + return Some((k.rect.x + k.rect.w / 2, k.rect.y + k.rect.h / 2)) + } + } + None +} + +///| Height of the on-screen keyboard when shown. +pub fn ChandraCompositor::osk_height(self : ChandraCompositor) -> Int { + let half = self.output_h / 2 + let h = if 236 < half { 236 } else { half } + if h < 120 { (120).min(self.output_h) } else { h } +} + +///| Bounding rectangle of the visible on-screen keyboard. +pub fn ChandraCompositor::osk_rect(self : ChandraCompositor) -> @scene.Rect { + let h = self.osk_height() + @scene.Rect::new(0, self.output_h - h, self.output_w, h) +} + +///| Compact "KB" pill above the bottom-right corner of the panel when the OSK is enabled but +/// currently hidden, letting users summon the keyboard anywhere manually. +pub fn ChandraCompositor::osk_toggle_rect(self : ChandraCompositor) -> @scene.Rect { + let w = 44 + let h = 28 + let x = (self.output_w - w - 6).max(4) + let y = (self.output_h - self.theme.panel_height - h - 6).max(4) + @scene.Rect::new(x, y, w, h) +} + +///| Show or hide the OSK, resizing `work_area` and lifting panel popups so focused content stays +/// above the keyboard. +fn ChandraCompositor::osk_set_visible(self : ChandraCompositor, want : Bool) -> Unit { + if self.osk_visible == want { + return + } + self.osk_visible = want + if !want { + self.osk_pressed = None + self.osk_hover = None + self.osk_pointer_grab = false + self.osk_shift = false + self.osk_ctrl = false + self.osk_alt = false + } + self.recompute_work_area() + match self.emoji_ui { + Some(ui) => self.emoji_place(ui) + None => () + } +} + +///| Synchronize OSK visibility with the active focus target (auth dialog, emoji picker, open +/// shell popup, active text-input-v3 or terminal window). +pub fn ChandraCompositor::osk_sync(self : ChandraCompositor) -> Unit { + if !self.osk_enabled { + if self.osk_visible { + self.osk_set_visible(false) + } + return + } + let (target, auto_want) : (String, Bool) = if self.auth is Some(_) { + ("auth", true) + } else if self.emoji_ui is Some(_) { + ("emoji", true) + } else if self.shell.popup_open() { + let mid = self.shell.open_popup_module_id() + let t = if mid.length() > 0 { "popup:" + mid } else { "menu" } + let aw = mid == "launcher" || (mid == "network" && self.osk_popup_typing) + (t, aw) + } else { + match self.kbd_win { + Some(wid) => { + let ti = self.server.text_input_active(wid) + let term = match self.windows.get(wid) { + Some(win) => osk_is_terminal_app(win.app_id) + None => false + } + let aw = ti || term + let ti_tag = if ti { ":ti1" } else { ":ti0" } + ("win:" + wid.to_string() + ti_tag, aw) + } + None => ("", false) + } + } + if target != self.osk_target { + let prev_ti = self.osk_target.has_prefix("win:") && self.osk_target.contains(":ti") + let next_ti = target.has_prefix("win:") && target.contains(":ti1") + self.osk_target = target + self.osk_manual_hide = false + // Transitioning out of non-popup contexts clears popup typing state. + if !target.has_prefix("popup:") { + self.osk_popup_typing = false + } + // Keep manual show only if staying off-auto wasn't invalidated by switching targets. + if !(prev_ti && next_ti && auto_want) { + self.osk_manual_show = false + } + } + let want = if self.osk_manual_hide { + false + } else { + auto_want || self.osk_manual_show + } + self.osk_set_visible(want) +} + +///| Notify the OSK when the user clicks inside an already-open shell popup (e.g. Launcher search +/// or Network password entry) so the keyboard opens or reopens after being hidden. +fn ChandraCompositor::osk_on_shell_click(self : ChandraCompositor, xi : Int, yi : Int) -> Unit { + if !self.osk_enabled { + return + } + let mid = self.shell.open_popup_module_id() + if mid == "launcher" { + self.osk_manual_hide = false + } else if mid == "network" { + match self.shell.open_popup_rect() { + Some(r) if r.contains(xi, yi) => { + self.osk_popup_typing = true + self.osk_manual_hide = false + } + _ => () + } + } +} + +///| Notify the OSK when the user clicks inside a client window's surface: if it has an active +/// text input or is a terminal (even after tapping Hide), bring the OSK back up. +fn ChandraCompositor::osk_on_window_click(self : ChandraCompositor, wid : UInt64) -> Unit { + if !self.osk_enabled { + return + } + let ti = self.server.text_input_active(wid) + let term = match self.windows.get(wid) { + Some(w) => osk_is_terminal_app(w.app_id) + None => false + } + if ti || term { + self.osk_manual_hide = false + } +} + +///| Lay out one row of keys inside `(rx, y, rw, h)`. `lead_units` adds half-key indentation (e.g. +/// `0.5` for the home row) within `total_units`. +fn osk_layout_row( + rx : Int, + y : Int, + rw : Int, + h : Int, + lead_units : Double, + total_units : Double, + specs : Array[(String, Double, OskAction, Bool, Bool)], + out : Array[OskKey], +) -> Unit { + let pad_x = 4 + let gap = 4 + let usable_w = (rw - pad_x * 2).max(40).to_double() + let mut cursor_u = lead_units + for sp in specs { + let (label, units, action, active, accent) = sp + let x0 = rx + pad_x + (cursor_u / total_units * usable_w).to_int() + let x1 = rx + pad_x + ((cursor_u + units) / total_units * usable_w).to_int() + let kw = (x1 - x0 - gap).max(12) + out.push({ rect: @scene.Rect::new(x0 + gap / 2, y, kw, h), label, action, active, accent }) + cursor_u = cursor_u + units + } +} + +///| Alpha/symbol letter label (capitalized when Shift is active). +fn osk_letter_label(s : String, upper : Bool) -> String { + if upper { s.to_upper() } else { s } +} + +///| Build all clickable keys for the current OSK state. +fn ChandraCompositor::osk_keys(self : ChandraCompositor) -> Array[OskKey] { + let r = self.osk_rect() + let keys : Array[OskKey] = [] + let top_pad = 5 + let bot_pad = 5 + let row_gap = 4 + let inner_h = (r.h - top_pad - bot_pad - row_gap * 4).max(80) + let h0 = (inner_h * 16 / 100).max(24).min(34) + let key_h = ((inner_h - h0) / 4).max(14) + let y0 = r.y + top_pad + let y1 = y0 + h0 + row_gap + let y2 = y1 + key_h + row_gap + let y3 = y2 + key_h + row_gap + let y4 = y3 + key_h + row_gap + + // Row 0: terminal/navigation utilities + Hide + osk_layout_row( + r.x, + y0, + r.w, + h0, + 0.0, + 10.0, + [ + ("Esc", 1.0, OskKeyCode(1U, false), false, false), + ("Tab", 1.0, OskKeyCode(15U, false), false, false), + ("Ctrl", 1.2, OskCtrl, self.osk_ctrl, false), + ("Alt", 1.1, OskAlt, self.osk_alt, false), + ("←", 1.0, OskKeyCode(105U, false), false, false), + ("↓", 1.0, OskKeyCode(108U, false), false, false), + ("↑", 1.0, OskKeyCode(103U, false), false, false), + ("→", 1.0, OskKeyCode(106U, false), false, false), + ("Hide", 1.7, OskHide, false, false), + ], + keys, + ) + + if !self.osk_sym { + let sh = self.osk_shift + // Row 1: q..p + let r1 : Array[(String, Double, OskAction, Bool, Bool)] = [] + let q_chars = ["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"] + for i, ch in q_chars { + r1.push( + (osk_letter_label(ch, sh), 1.0, OskKeyCode((16 + i).reinterpret_as_uint(), false), false, false), + ) + } + osk_layout_row(r.x, y1, r.w, key_h, 0.0, 10.0, r1, keys) + + // Row 2: a..l + let r2 : Array[(String, Double, OskAction, Bool, Bool)] = [] + let a_chars = ["a", "s", "d", "f", "g", "h", "j", "k", "l"] + for i, ch in a_chars { + r2.push( + (osk_letter_label(ch, sh), 1.0, OskKeyCode((30 + i).reinterpret_as_uint(), false), false, false), + ) + } + osk_layout_row(r.x, y2, r.w, key_h, 0.5, 10.0, r2, keys) + + // Row 3: Shift z..m Backspace + let r3 : Array[(String, Double, OskAction, Bool, Bool)] = [ + ("Shift", 1.5, OskShift, self.osk_shift, false), + ] + let z_chars = ["z", "x", "c", "v", "b", "n", "m"] + for i, ch in z_chars { + r3.push( + (osk_letter_label(ch, sh), 1.0, OskKeyCode((44 + i).reinterpret_as_uint(), false), false, false), + ) + } + r3.push(("⌫", 1.5, OskKeyCode(14U, false), false, false)) + osk_layout_row(r.x, y3, r.w, key_h, 0.0, 10.0, r3, keys) + + // Row 4: 123 , Space . Enter + osk_layout_row( + r.x, + y4, + r.w, + key_h, + 0.0, + 10.0, + [ + ("123", 1.5, OskSym, false, false), + (",", 1.0, OskKeyCode(51U, false), false, false), + ("Space", 4.5, OskKeyCode(57U, false), false, false), + (".", 1.0, OskKeyCode(52U, false), false, false), + ("↵", 2.0, OskKeyCode(28U, false), false, true), + ], + keys, + ) + } else { + // Symbols Row 1: 1..0 + let r1 : Array[(String, Double, OskAction, Bool, Bool)] = [] + let digits = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] + for i, d in digits { + r1.push((d, 1.0, OskKeyCode((2 + i).reinterpret_as_uint(), false), false, false)) + } + osk_layout_row(r.x, y1, r.w, key_h, 0.0, 10.0, r1, keys) + + // Symbols Row 2: !..) + let r2 : Array[(String, Double, OskAction, Bool, Bool)] = [] + let syms = ["!", "@", "#", "$", "%", "^", "&", "*", "(", ")"] + for i, s in syms { + r2.push((s, 1.0, OskKeyCode((2 + i).reinterpret_as_uint(), true), false, false)) + } + osk_layout_row(r.x, y2, r.w, key_h, 0.0, 10.0, r2, keys) + + // Symbols Row 3: common punctuation & shell operators + Backspace + osk_layout_row( + r.x, + y3, + r.w, + key_h, + 0.0, + 10.0, + [ + ("-", 0.95, OskKeyCode(12U, false), false, false), + ("_", 0.95, OskKeyCode(12U, true), false, false), + ("=", 0.95, OskKeyCode(13U, false), false, false), + ("+", 0.95, OskKeyCode(13U, true), false, false), + ("/", 0.95, OskKeyCode(53U, false), false, false), + ("\\", 0.95, OskKeyCode(43U, false), false, false), + (":", 0.95, OskKeyCode(39U, true), false, false), + ("'", 0.95, OskKeyCode(40U, false), false, false), + ("?", 0.95, OskKeyCode(53U, true), false, false), + ("⌫", 1.45, OskKeyCode(14U, false), false, false), + ], + keys, + ) + + // Symbols Row 4: ABC ; " Space ~ | Enter + osk_layout_row( + r.x, + y4, + r.w, + key_h, + 0.0, + 10.0, + [ + ("ABC", 1.5, OskSym, true, false), + (";", 1.0, OskKeyCode(39U, false), false, false), + ("\"", 1.0, OskKeyCode(40U, true), false, false), + ("Space", 2.5, OskKeyCode(57U, false), false, false), + ("~", 1.0, OskKeyCode(41U, true), false, false), + ("|", 1.0, OskKeyCode(43U, true), false, false), + ("↵", 2.0, OskKeyCode(28U, false), false, true), + ], + keys, + ) + } + keys +} + +///| Key index at screen position `(x, y)`, if any. +fn ChandraCompositor::osk_key_at(self : ChandraCompositor, x : Int, y : Int) -> Int? { + if !self.osk_visible || !self.osk_rect().contains(x, y) { + return None + } + let keys = self.osk_keys() + for i, k in keys { + if k.rect.contains(x, y) { + return Some(i) + } + } + None +} + +///| Whether `(x, y)` hits either the open OSK or its compact reopen pill. +fn ChandraCompositor::osk_hit_any(self : ChandraCompositor, x : Int, y : Int) -> Bool { + if !self.osk_enabled { + return false + } + if self.osk_visible { + self.osk_rect().contains(x, y) + } else { + !self.kiosk_strict() && self.osk_toggle_rect().contains(x, y) + } +} + +///| Route one virtual key press+release to the active target (auth dialog, emoji picker, open +/// shell popup, focused Wayland client, or focused desktop module). +fn ChandraCompositor::osk_send_key( + self : ChandraCompositor, + code : UInt, + implicit_shift : Bool, + time_ms : UInt, +) -> Unit { + let shift = implicit_shift || self.osk_shift + let ctrl = self.osk_ctrl + let alt = self.osk_alt + let mod_bits : UInt = (if shift { 1U } else { 0U }) | + (if ctrl { 4U } else { 0U }) | + (if alt { 8U } else { 0U }) + match self.auth { + Some(ui) => { + let saved_mods = self.mods + let saved_lat = self.mods_latched + self.mods = mod_bits + self.mods_latched = 0U + ignore(self.auth_input(ui, @nested.InputEvent::Key(code, true))) + if self.auth is Some(ui2) { + ignore(self.auth_input(ui2, @nested.InputEvent::Key(code, false))) + } + self.mods = saved_mods + self.mods_latched = saved_lat + } + None => + if self.emoji_ui is Some(_) { + let saved_mods = self.mods + let saved_lat = self.mods_latched + self.mods = mod_bits + self.mods_latched = 0U + ignore(self.emoji_input(@nested.InputEvent::Key(code, true), time_ms)) + if self.emoji_ui is Some(_) { + ignore(self.emoji_input(@nested.InputEvent::Key(code, false), time_ms + 1U)) + } + self.mods = saved_mods + self.mods_latched = saved_lat + } else if self.shell.popup_open() { + let name = key_name(code, shift) + if name.length() > 0 { + self.shell.key_down(name) + self.run_shell_actions() + } + } else { + match self.kbd_win { + Some(wid) => { + let need_mod = mod_bits != self.mods || self.mods_latched != 0U + if need_mod { + self.server.keyboard_modifiers(wid, mod_bits, 0U, self.mods_locked, self.mods_group) + } + self.server.keyboard_key(wid, time_ms, code, true) + self.server.keyboard_key(wid, time_ms + 1U, code, false) + if need_mod { + self.server.keyboard_modifiers( + wid, + self.mods, + self.mods_latched, + self.mods_locked, + self.mods_group, + ) + } + } + None => + if self.shell.desktop_has_focus() { + let name = key_name(code, shift) + if name.length() > 0 && self.shell.desktop_key(name) { + self.run_shell_actions() + } + } + } + } + } + self.osk_shift = false + self.osk_ctrl = false + self.osk_alt = false +} + +///| Execute the action of key `idx`. +fn ChandraCompositor::osk_activate_key( + self : ChandraCompositor, + idx : Int, + time_ms : UInt, +) -> Unit { + let keys = self.osk_keys() + if idx < 0 || idx >= keys.length() { + return + } + match keys[idx].action { + OskKeyCode(code, implicit_shift) => self.osk_send_key(code, implicit_shift, time_ms) + OskShift => self.osk_shift = !self.osk_shift + OskCtrl => self.osk_ctrl = !self.osk_ctrl + OskAlt => self.osk_alt = !self.osk_alt + OskSym => { + self.osk_sym = !self.osk_sym + self.osk_shift = false + } + OskHide => { + self.osk_manual_hide = true + self.osk_manual_show = false + self.osk_set_visible(false) + } + } + self.damage.mark_full() +} + +///| Handle host input when over the OSK or its toggle pill. True if consumed. +fn ChandraCompositor::osk_input( + self : ChandraCompositor, + ev : @nested.InputEvent, + time_ms : UInt, +) -> Bool { + if !self.osk_enabled { + return false + } + match ev { + PointerMove(x, y) => { + self.ptr_x = x + self.ptr_y = y + let xi = x.to_int() + let yi = y.to_int() + if self.osk_visible { + if self.osk_pointer_grab || self.osk_rect().contains(xi, yi) { + let h = self.osk_key_at(xi, yi) + if h != self.osk_hover { + self.osk_hover = h + self.damage.mark_full() + } + return true + } + if self.osk_hover is Some(_) { + self.osk_hover = None + self.damage.mark_full() + } + return false + } + if !self.kiosk_strict() && self.osk_toggle_rect().contains(xi, yi) { + if self.osk_hover != Some(-1) { + self.osk_hover = Some(-1) + self.damage.mark_full() + } + return true + } + if self.osk_hover == Some(-1) { + self.osk_hover = None + self.damage.mark_full() + } + false + } + PointerButton(button, pressed) => { + let xi = self.ptr_x.to_int() + let yi = self.ptr_y.to_int() + if !pressed && button == 272U && self.osk_pointer_grab { + self.osk_pointer_grab = false + let idx_opt = self.osk_pressed + self.osk_pressed = None + self.damage.mark_full() + match idx_opt { + Some(-1) => + if !self.osk_visible && !self.kiosk_strict() && self.osk_toggle_rect().contains(xi, yi) { + self.osk_manual_hide = false + self.osk_manual_show = true + self.osk_sync() + } + Some(idx) => + if self.osk_visible && self.osk_key_at(xi, yi) == Some(idx) { + self.osk_activate_key(idx, time_ms) + self.osk_sync() + } + None => () + } + return true + } + if self.osk_visible && self.osk_rect().contains(xi, yi) { + if button == 272U && pressed { + self.osk_pointer_grab = true + self.osk_pressed = self.osk_key_at(xi, yi) + self.damage.mark_full() + } + return true + } + if !self.osk_visible && !self.kiosk_strict() && self.osk_toggle_rect().contains(xi, yi) { + if button == 272U && pressed { + self.osk_pointer_grab = true + self.osk_pressed = Some(-1) + self.damage.mark_full() + } + return true + } + false + } + Scroll(_, _, _) => { + let xi = self.ptr_x.to_int() + let yi = self.ptr_y.to_int() + if (self.osk_visible && self.osk_rect().contains(xi, yi)) || self.osk_pointer_grab { + return true + } + false + } + _ => false + } +} + +///| Draw the OSK or its compact summon pill when enabled. +fn ChandraCompositor::osk_ops(self : ChandraCompositor) -> Array[@scene.DrawOp] { + let ops : Array[@scene.DrawOp] = [] + if !self.osk_enabled { + return ops + } + let pal = self.theme.palette + let fs = self.theme.font_size + let rad = self.theme.radius + if !self.osk_visible { + if self.kiosk_strict() { + return ops + } + let tr = self.osk_toggle_rect() + let bg = if self.osk_pressed == Some(-1) { + pal.accent + } else if self.osk_hover == Some(-1) { + pal.surface_hover + } else { + @scene.Rgba::new(pal.surface_popup.r.to_int(), pal.surface_popup.g.to_int(), pal.surface_popup.b.to_int(), 230) + } + let fg = if self.osk_pressed == Some(-1) { pal.accent_foreground } else { pal.foreground } + ops.push(@scene.DrawOp::FillRect(tr, bg, rad + 4)) + ops.push(@scene.DrawOp::StrokeRect(tr, pal.border, 1, rad + 4)) + ops.push(@scene.DrawOp::Text(tr.x + tr.w / 2, tr.y + tr.h / 2, "KB", (fs - 2).max(10), fg, @scene.TextAlign::Center, true)) + return ops + } + let r = self.osk_rect() + let panel_bg = @scene.Rgba::new(pal.surface_popup.r.to_int(), pal.surface_popup.g.to_int(), pal.surface_popup.b.to_int(), 248) + ops.push(@scene.DrawOp::FillRect(r, panel_bg, 0)) + ops.push(@scene.DrawOp::FillRect(@scene.Rect::new(r.x, r.y, r.w, 1), pal.border, 0)) + let keys = self.osk_keys() + let krad = rad.min(8).max(4) + for i, k in keys { + let down = self.osk_pressed == Some(i) + let lit = k.active || down || k.accent + let kbg = if lit { + pal.accent + } else if self.osk_hover == Some(i) { + pal.surface_hover + } else { + pal.surface + } + let kfg = if lit { pal.accent_foreground } else { pal.foreground } + let kfs = if k.label.length() > 1 { (fs - 2).max(10) } else { fs } + ops.push(@scene.DrawOp::FillRect(k.rect, kbg, krad)) + ops.push(@scene.DrawOp::StrokeRect(k.rect, pal.border, 1, krad)) + ops.push(@scene.DrawOp::Text(k.rect.x + k.rect.w / 2, k.rect.y + k.rect.h / 2, k.label, kfs, kfg, @scene.TextAlign::Center, lit)) + } + ops +} diff --git a/compositor/host/osk_test.mbt b/compositor/host/osk_test.mbt new file mode 100644 index 0000000..d966f19 --- /dev/null +++ b/compositor/host/osk_test.mbt @@ -0,0 +1,139 @@ +///| Built-in on-screen keyboard (osk.mbt): auto-open on text-input-v3 and terminal/launcher +/// focus, work_area resizing, popup lifting, virtual evdev key + Shift delivery, and Hide/reopen. + +///| +fn osk_comp(tag : String, enable_osk? : Bool = true) -> @host.ChandraCompositor { + let socket_path = "/tmp/wayland-moon-osk-" + tag + "-" + @sys.getpid().to_string() + ".sock" + let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 540, 1170).unwrap() + if enable_osk { + comp.set_osk_enabled(true) + } + ignore(comp.compose_frame()) + comp +} + +///| +test "OSK stays disabled under CHANDRA_TEST_CONFIG=1 unless explicitly enabled" { + let socket_path = "/tmp/wayland-moon-osk-disabled-" + @sys.getpid().to_string() + ".sock" + let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 540, 1170).unwrap() + let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Editor", "editor") + commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL) + let (ti, _) = text_input_for(comp, a) + text_input_state(comp, a, ti, true, 50, 50, 16) + assert_false(comp.osk_is_visible()) + comp.close() +} + +///| +test "OSK auto-opens on zwp_text_input_v3 enable, shrinks work_area, and auto-hides on disable" { + let socket_path = "/tmp/wayland-moon-osk-ti-" + @sys.getpid().to_string() + ".sock" + let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 540, 1170).unwrap() + comp.set_osk_enabled(true) + let full_wa_h = comp.work_area.h + let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Editor", "editor") + commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL) + assert_eq(comp.kbd_win, Some(1UL)) + let (ti, _) = text_input_for(comp, a) + assert_false(comp.osk_is_visible()) + + // Enabling text-input-v3 raises the OSK and shrinks the window work area cleanly above it. + text_input_state(comp, a, ti, true, 50, 50, 16) + assert_true(comp.osk_is_visible()) + assert_eq(comp.work_area.h, full_wa_h - (comp.osk_height() - comp.theme.panel_height)) + + // Disabling text-input-v3 hides the OSK and restores the full work area. + text_input_state(comp, a, ti, false, 0, 0, 0) + assert_false(comp.osk_is_visible()) + assert_eq(comp.work_area.h, full_wa_h) + comp.close() +} + +///| +test "OSK delivers evdev keys and one-shot Shift modifier to focused Wayland client" { + let socket_path = "/tmp/wayland-moon-osk-keys-" + @sys.getpid().to_string() + ".sock" + let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 540, 1170).unwrap() + comp.set_osk_enabled(true) + let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Editor", "editor") + commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL) + let (ti, kbd) = text_input_for(comp, a) + text_input_state(comp, a, ti, true, 50, 50, 16) + assert_true(comp.osk_is_visible()) + ignore(drain_args(a)) + + // Tap 'a' (evdev 30) -> press + release sent via wl_keyboard.key (opcode 3). + let (ax, ay) = comp.osk_key_center("a").unwrap() + click_at(comp, ax, ay, 20U) + let msgs1 = drain_args(a) + let keys1 = msgs1.filter(m => m.0 == kbd && m.1 == 3U) + assert_eq(keys1.length(), 2) + assert_eq((keys1[0].2[2], keys1[0].2[3]), (30U, 1U)) + assert_eq((keys1[1].2[2], keys1[1].2[3]), (30U, 0U)) + + // Tap 'Shift', verify key labels uppercase, tap 'A' -> Shift mod active then released. + let (sx, sy) = comp.osk_key_center("Shift").unwrap() + click_at(comp, sx, sy, 30U) + let (ux, uy) = comp.osk_key_center("A").unwrap() + click_at(comp, ux, uy, 40U) + let msgs2 = drain_args(a) + let mods2 = msgs2.filter(m => m.0 == kbd && m.1 == 4U) + let keys2 = msgs2.filter(m => m.0 == kbd && m.1 == 3U) + assert_true(mods2.length() >= 2) + assert_eq(mods2[0].2[1], 1U) // Shift depressed + assert_eq(mods2[mods2.length() - 1].2[1], 0U) // Restored + assert_eq(keys2.length(), 2) + assert_eq((keys2[0].2[2], keys2[0].2[3]), (30U, 1U)) + assert_eq((keys2[1].2[2], keys2[1].2[3]), (30U, 0U)) + // One-shot Shift cleared back to lowercase. + assert_true(comp.osk_key_center("a") is Some(_)) + comp.close() +} + +///| +test "OSK Hide button dismisses keyboard and KB pill or client tap reopens it" { + let socket_path = "/tmp/wayland-moon-osk-hide-" + @sys.getpid().to_string() + ".sock" + let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 540, 1170).unwrap() + comp.set_osk_enabled(true) + let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Notes", "notes") + commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL) + let (ti, _) = text_input_for(comp, a) + text_input_state(comp, a, ti, true, 50, 50, 16) + assert_true(comp.osk_is_visible()) + + // Hide button hides the keyboard. + let (hx, hy) = comp.osk_key_center("Hide").unwrap() + click_at(comp, hx, hy, 20U) + assert_false(comp.osk_is_visible()) + + // Tapping the compact "KB" toggle pill reopens it. + let tr = comp.osk_toggle_rect() + click_at(comp, tr.x + tr.w / 2, tr.y + tr.h / 2, 30U) + assert_true(comp.osk_is_visible()) + + // Hide again, then tap inside the client window with active text input -> reopens. + let (hx2, hy2) = comp.osk_key_center("Hide").unwrap() + click_at(comp, hx2, hy2, 40U) + assert_false(comp.osk_is_visible()) + let g = comp.windows.get(1UL).unwrap().geometry + click_at(comp, g.x + g.w / 2, g.y + g.h / 2, 50U) + assert_true(comp.osk_is_visible()) + comp.close() +} + +///| +test "OSK auto-opens on launcher popup, lifts popup above OSK, and types into search" { + let comp = osk_comp("launcher") + let (lx, ly) = center_of(comp, "launcher") + click_at(comp, lx.to_int(), ly.to_int(), 10U) + assert_true(comp.shell.popup_open()) + assert_true(comp.osk_is_visible()) + + // Launcher popup sits entirely above the OSK. + let pr = comp.shell.open_popup_rect().unwrap() + assert_true(pr.y + pr.h <= comp.osk_rect().y) + + // Tapping a letter key updates the launcher search query. + let (tx, ty) = comp.osk_key_center("t").unwrap() + click_at(comp, tx, ty, 20U) + assert_eq(comp.shell.launcher_state.query, "t") + comp.close() +} diff --git a/compositor/host/screenshot.mbt b/compositor/host/screenshot.mbt index af4ac05..7482c1a 100644 --- a/compositor/host/screenshot.mbt +++ b/compositor/host/screenshot.mbt @@ -217,6 +217,30 @@ fn ChandraCompositor::freeze_screen(self : ChandraCompositor) -> @renderer.Pixma } } +///| Capture the current screen directly to PNG bytes without opening the editor. +pub fn ChandraCompositor::capture_png(self : ChandraCompositor) -> Bytes? { + let full = @scene.Rect::new(0, 0, self.output_w, self.output_h) + match self.frame_shots { + Some(host) => + if (host.snapshot)() { + let png = (host.png)(full) + if png.length() > 0 { Some(png) } else { None } + } else { + None + } + None => + match self.grab_screen() { + Some(frame) => { + for i = 3; i < frame.data.length(); i = i + 4 { + frame.data[i] = b'\xff' + } + Some(@renderer.encode_png_compressed(frame)) + } + None => None + } + } +} + ///| A window's rectangle on screen with its title bar and borders (Spectacle's default). fn ChandraCompositor::outer_rect(self : ChandraCompositor, wid : UInt64) -> @scene.Rect? { match self.windows.get(wid) { diff --git a/compositor/kms/kms_native.mbt b/compositor/kms/kms_native.mbt index 97f51d0..c20ba44 100644 --- a/compositor/kms/kms_native.mbt +++ b/compositor/kms/kms_native.mbt @@ -150,7 +150,7 @@ pub fn Kms::present_frame(_self : Kms) -> Unit { ///| The seat, DRM and input fds `poll` services, for an idle loop to block on. pub fn Kms::wait_fds(_self : Kms) -> Array[Int] { let out : Array[Int] = [] - for i = 0; i < 3; i = i + 1 { + for i = 0; i < 4; i = i + 1 { let fd = c_fd(i) if fd >= 0 { out.push(fd) diff --git a/compositor/kms/kms_stub.c b/compositor/kms/kms_stub.c index 200845a..a070dd4 100644 --- a/compositor/kms/kms_stub.c +++ b/compositor/kms/kms_stub.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -32,6 +33,9 @@ #define KEY_F11_CODE 87 #define KEY_F12_CODE 88 #define BTN_LEFT_CODE 0x110 +#define BTN_RIGHT_CODE 0x111 +#define TOUCH_LONG_MS 500 +#define TOUCH_DRAG_PX 12 /* ---- damage ---- */ @@ -142,6 +146,9 @@ static int g_front; /* index currently scanned out */ static int g_flip_pending; static int g_need_modeset; static int g_width, g_height; +static int g_phys_w, g_phys_h; +static uint32_t g_mm_w, g_mm_h; +static int g_scale = 1; static int g_blank; /* screen turned off (DPMS) by mp_kms_set_power */ static int fb_create(struct fbuf *b, int w, int h) { @@ -189,6 +196,7 @@ static int pick_output(int fd) { } if (crtc) { g_conn = c->connector_id; g_crtc = crtc; g_mode = c->modes[mi]; + g_mm_w = c->mmWidth; g_mm_h = c->mmHeight; ok = 0; } } @@ -206,8 +214,11 @@ static int g_cur_ready; static int g_cur_shape = -1; static int g_px, g_py; /* pointer position (hotspot) */ static int g_hotx, g_hoty; -static int g_touch_active; +enum { TOUCH_IDLE = 0, TOUCH_PENDING = 1, TOUCH_DRAG = 2, TOUCH_LONG = 3 }; +static int g_touch_state; static int32_t g_touch_slot; +static int g_touch_x0, g_touch_y0; +static int g_touch_timer = -1; static const char *ART_ARROW[] = { "X...........", "XX..........", "XoX.........", "XooX........", "XoooX.......", @@ -228,13 +239,26 @@ static void cursor_draw(int shape) { g_hotx = 0; g_hoty = 0; if (shape == 4) { art = ART_HAND; g_hotx = 5; g_hoty = 0; } else if (shape == 9) { art = ART_IBEAM; g_hotx = 3; g_hoty = 7; } + int sc = g_scale > 1 ? g_scale : 1; + if (sc > 3) sc = 3; + g_hotx *= sc; + g_hoty *= sc; uint32_t *px = (uint32_t *)g_cur_buf.map; memset(px, 0, (size_t)CUR * CUR * 4); - for (int y = 0; art[y] && y < CUR; y++) { - for (int x = 0; art[y][x] && x < CUR; x++) { + for (int y = 0; art[y]; y++) { + for (int x = 0; art[y][x]; x++) { char ch = art[y][x]; - if (ch == 'X') px[y * (g_cur_buf.pitch / 4) + x] = 0xFF000000u; - else if (ch == 'o') px[y * (g_cur_buf.pitch / 4) + x] = 0xFFFFFFFFu; + if (ch != 'X' && ch != 'o') continue; + uint32_t col = ch == 'X' ? 0xFF000000u : 0xFFFFFFFFu; + for (int sy = 0; sy < sc; sy++) { + int py = y * sc + sy; + if (py >= CUR) break; + for (int sx = 0; sx < sc; sx++) { + int px_i = x * sc + sx; + if (px_i >= CUR) break; + px[py * (g_cur_buf.pitch / 4) + px_i] = col; + } + } } } } @@ -242,7 +266,31 @@ static void cursor_draw(int shape) { static void cursor_apply(void) { if (!g_cur_ready || !g_seat_enabled) return; drmModeSetCursor(g_drm, g_crtc, g_cur_buf.handle, CUR, CUR); - drmModeMoveCursor(g_drm, g_crtc, g_px - g_hotx, g_py - g_hoty); + drmModeMoveCursor(g_drm, g_crtc, g_px * g_scale - g_hotx, g_py * g_scale - g_hoty); +} + +/* ---- touch long-press timer ---------------------------------------------- */ + +static void touch_timer_arm(int ms) { + if (g_touch_timer < 0) return; + struct itimerspec its = {0}; + its.it_value.tv_sec = ms / 1000; + its.it_value.tv_nsec = (long)(ms % 1000) * 1000000L; + timerfd_settime(g_touch_timer, 0, &its, NULL); +} + +static void touch_timer_disarm(void) { + if (g_touch_timer < 0) return; + struct itimerspec its = {0}; + timerfd_settime(g_touch_timer, 0, &its, NULL); +} + +static void touch_cancel(void) { + touch_timer_disarm(); + if (g_touch_state == TOUCH_DRAG) { + q_push(EV_BUTTON, BTN_LEFT_CODE, 0, 0, 0); + } + g_touch_state = TOUCH_IDLE; } /* ---- xkb + libinput ------------------------------------------------------ */ @@ -338,35 +386,64 @@ static void handle_li_event(struct libinput_event *ev) { } case LIBINPUT_EVENT_TOUCH_DOWN: { struct libinput_event_touch *t = libinput_event_get_touch_event(ev); - if (!g_touch_active) { - g_touch_active = 1; + if (g_touch_state == TOUCH_IDLE) { g_touch_slot = libinput_event_touch_get_seat_slot(t); g_px = (int)libinput_event_touch_get_x_transformed(t, (uint32_t)g_width); g_py = (int)libinput_event_touch_get_y_transformed(t, (uint32_t)g_height); clamp_pointer(); + g_touch_x0 = g_px; + g_touch_y0 = g_py; + g_touch_state = TOUCH_PENDING; q_push(EV_MOVE, g_px, g_py, 0, 0); - q_push(EV_BUTTON, BTN_LEFT_CODE, 1, 0, 0); cursor_apply(); + touch_timer_arm(TOUCH_LONG_MS); } break; } case LIBINPUT_EVENT_TOUCH_MOTION: { struct libinput_event_touch *t = libinput_event_get_touch_event(ev); - if (g_touch_active && libinput_event_touch_get_seat_slot(t) == g_touch_slot) { + if (g_touch_state != TOUCH_IDLE && libinput_event_touch_get_seat_slot(t) == g_touch_slot) { g_px = (int)libinput_event_touch_get_x_transformed(t, (uint32_t)g_width); g_py = (int)libinput_event_touch_get_y_transformed(t, (uint32_t)g_height); clamp_pointer(); - q_push(EV_MOVE, g_px, g_py, 0, 0); - cursor_apply(); + if (g_touch_state == TOUCH_PENDING) { + int dx = g_px - g_touch_x0; + int dy = g_py - g_touch_y0; + if (dx < -TOUCH_DRAG_PX || dx > TOUCH_DRAG_PX || dy < -TOUCH_DRAG_PX || dy > TOUCH_DRAG_PX) { + touch_timer_disarm(); + g_touch_state = TOUCH_DRAG; + q_push(EV_MOVE, g_touch_x0, g_touch_y0, 0, 0); + q_push(EV_BUTTON, BTN_LEFT_CODE, 1, 0, 0); + q_push(EV_MOVE, g_px, g_py, 0, 0); + cursor_apply(); + } + } else if (g_touch_state == TOUCH_DRAG) { + q_push(EV_MOVE, g_px, g_py, 0, 0); + cursor_apply(); + } + } + break; + } + case LIBINPUT_EVENT_TOUCH_UP: { + struct libinput_event_touch *t = libinput_event_get_touch_event(ev); + if (g_touch_state != TOUCH_IDLE && libinput_event_touch_get_seat_slot(t) == g_touch_slot) { + int st = g_touch_state; + touch_timer_disarm(); + g_touch_state = TOUCH_IDLE; + if (st == TOUCH_PENDING) { + q_push(EV_MOVE, g_px, g_py, 0, 0); + q_push(EV_BUTTON, BTN_LEFT_CODE, 1, 0, 0); + q_push(EV_BUTTON, BTN_LEFT_CODE, 0, 0, 0); + } else if (st == TOUCH_DRAG) { + q_push(EV_BUTTON, BTN_LEFT_CODE, 0, 0, 0); + } } break; } - case LIBINPUT_EVENT_TOUCH_UP: case LIBINPUT_EVENT_TOUCH_CANCEL: { struct libinput_event_touch *t = libinput_event_get_touch_event(ev); - if (g_touch_active && libinput_event_touch_get_seat_slot(t) == g_touch_slot) { - g_touch_active = 0; - q_push(EV_BUTTON, BTN_LEFT_CODE, 0, 0, 0); + if (g_touch_state != TOUCH_IDLE && libinput_event_touch_get_seat_slot(t) == g_touch_slot) { + touch_cancel(); } break; } @@ -429,6 +506,36 @@ void mp_kms_set_power(int32_t on) { } +static int is_handset_chassis(void) { + FILE *f = fopen("/etc/machine-info", "r"); + if (!f) return 0; + char buf[1024]; + size_t n = fread(buf, 1, sizeof buf - 1, f); + fclose(f); + buf[n] = '\0'; + return strstr(buf, "CHASSIS=handset") != NULL; +} + +static int pick_scale(int pw, int ph, uint32_t mm_w, uint32_t mm_h) { + const char *env = getenv("CHANDRA_SCALE"); + if (env && *env) { + int s = atoi(env); + if (s < 1) s = 1; + if (s > 4) s = 4; + return s; + } + int dpi = 0; + if (mm_w > 0 && mm_h > 0) { + int dx = (int)((double)pw * 25.4 / (double)mm_w); + int dy = (int)((double)ph * 25.4 / (double)mm_h); + dpi = dx > dy ? dx : dy; + } + if ((dpi >= 200 || is_handset_chassis()) && pw >= 800 && ph >= 800) { + return 2; + } + return 1; +} + /* Open seat, DRM output and input. Returns 0 on success, negative step code on failure. */ MOONBIT_FFI_EXPORT int32_t mp_kms_open(void) { @@ -448,10 +555,18 @@ int32_t mp_kms_open(void) { else { libseat_close_device(g_seat, id); close(fd); } } if (g_drm < 0) { fprintf(stderr, "kms: no DRM device with a connected display\n"); return -3; } - g_width = g_mode.hdisplay; g_height = g_mode.vdisplay; + g_phys_w = g_mode.hdisplay; + g_phys_h = g_mode.vdisplay; + g_scale = pick_scale(g_phys_w, g_phys_h, g_mm_w, g_mm_h); + g_width = g_phys_w / g_scale; + g_height = g_phys_h / g_scale; + if (g_scale > 1) { + fprintf(stderr, "kms: output %dx%d scale %dx -> logical %dx%d\n", + g_phys_w, g_phys_h, g_scale, g_width, g_height); + } g_saved_crtc = drmModeGetCrtc(g_drm, g_crtc); - if (fb_create(&g_fb[0], g_width, g_height) < 0 || fb_create(&g_fb[1], g_width, g_height) < 0) { + if (fb_create(&g_fb[0], g_phys_w, g_phys_h) < 0 || fb_create(&g_fb[1], g_phys_w, g_phys_h) < 0) { fprintf(stderr, "kms: cannot create framebuffers\n"); return -4; } @@ -481,6 +596,7 @@ int32_t mp_kms_open(void) { fprintf(stderr, "kms: cannot start libinput on seat %s\n", g_seat ? libseat_seat_name(g_seat) : "?"); return -6; } + g_touch_timer = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC); dispatch_input(); return 0; } @@ -493,12 +609,13 @@ MOONBIT_FFI_EXPORT int32_t mp_kms_quit_requested(void) { return g_quit; } MOONBIT_FFI_EXPORT int32_t mp_kms_poll(void) { if (!g_seat) return 0; - struct pollfd pfd[3]; + struct pollfd pfd[4]; int n = 0; pfd[n].fd = libseat_get_fd(g_seat); pfd[n].events = POLLIN; n++; pfd[n].fd = g_drm; pfd[n].events = POLLIN; n++; int lifd = g_li ? libinput_get_fd(g_li) : -1; pfd[n].fd = lifd; pfd[n].events = POLLIN; n++; + pfd[n].fd = g_touch_timer; pfd[n].events = POLLIN; n++; poll(pfd, (nfds_t)n, 0); libseat_dispatch(g_seat, 0); if (pfd[1].revents & POLLIN) { @@ -509,10 +626,7 @@ int32_t mp_kms_poll(void) { /* VT switched away: stop input, give up DRM master, acknowledge. */ g_seat_lost = 0; g_suspended = 1; - if (g_touch_active) { - g_touch_active = 0; - q_push(EV_BUTTON, BTN_LEFT_CODE, 0, 0, 0); - } + touch_cancel(); if (g_li) libinput_suspend(g_li); drmDropMaster(g_drm); libseat_disable_seat(g_seat); @@ -525,11 +639,24 @@ int32_t mp_kms_poll(void) { if (g_blank) set_dpms(0); } if (g_li) dispatch_input(); + if (g_touch_timer >= 0 && (pfd[3].revents & POLLIN)) { + uint64_t exp = 0; + while (read(g_touch_timer, &exp, sizeof exp) > 0) {} + if (g_touch_state == TOUCH_PENDING) { + g_touch_state = TOUCH_LONG; + g_px = g_touch_x0; + g_py = g_touch_y0; + q_push(EV_MOVE, g_px, g_py, 0, 0); + q_push(EV_BUTTON, BTN_RIGHT_CODE, 1, 0, 0); + q_push(EV_BUTTON, BTN_RIGHT_CODE, 0, 0, 0); + cursor_apply(); + } + } return g_seat_enabled; } -/* The fds mp_kms_poll services (0 seat, 1 DRM, 2 libinput), for an idle loop to block on; - -1 when not open. */ +/* The fds mp_kms_poll services (0 seat, 1 DRM, 2 libinput, 3 touch timer), for an idle loop to + block on; -1 when not open. */ MOONBIT_FFI_EXPORT int32_t mp_kms_fd(int32_t i) { if (!g_seat) return -1; @@ -537,6 +664,7 @@ int32_t mp_kms_fd(int32_t i) { case 0: return libseat_get_fd(g_seat); case 1: return g_drm; case 2: return g_li ? libinput_get_fd(g_li) : -1; + case 3: return g_touch_timer; default: return -1; } } @@ -549,12 +677,39 @@ int32_t mp_kms_frame_ready(void) { /* RGBA8888 rows -> the scanout buffer's XRGB8888 (B, G, R, X), one pixel as one 32-bit word. */ static void copy_rows(struct fbuf *b, const uint8_t *src, int w, int x0, int y0, int x1, int y1) { + if (g_scale <= 1) { + for (int y = y0; y < y1; y++) { + uint32_t *d = (uint32_t *)(b->map + (size_t)y * b->pitch); + const uint32_t *s = (const uint32_t *)(src + (size_t)y * (size_t)w * 4); + for (int x = x0; x < x1; x++) { + uint32_t v = s[x]; + d[x] = 0xff000000u | (v & 0x0000ff00u) | ((v >> 16) & 0xffu) | ((v & 0xffu) << 16); + } + } + return; + } + int sc = g_scale; + int px0 = x0 * sc; + int px1 = x1 * sc; + if (px1 > g_phys_w) px1 = g_phys_w; + if (px0 >= px1) return; + size_t row_bytes = (size_t)(px1 - px0) * 4; for (int y = y0; y < y1; y++) { - uint32_t *d = (uint32_t *)(b->map + (size_t)y * b->pitch); + int py0 = y * sc; + if (py0 >= g_phys_h) break; + uint32_t *d0 = (uint32_t *)(b->map + (size_t)py0 * b->pitch); const uint32_t *s = (const uint32_t *)(src + (size_t)y * (size_t)w * 4); for (int x = x0; x < x1; x++) { uint32_t v = s[x]; - d[x] = 0xff000000u | (v & 0x0000ff00u) | ((v >> 16) & 0xffu) | ((v & 0xffu) << 16); + uint32_t c = 0xff000000u | (v & 0x0000ff00u) | ((v >> 16) & 0xffu) | ((v & 0xffu) << 16); + int dx = x * sc; + for (int k = 0; k < sc && dx + k < g_phys_w; k++) { + d0[dx + k] = c; + } + } + for (int sy = 1; sy < sc && py0 + sy < g_phys_h; sy++) { + uint8_t *dy = b->map + (size_t)(py0 + sy) * b->pitch + (size_t)px0 * 4; + memcpy(dy, (const uint8_t *)(d0 + px0), row_bytes); } } } @@ -649,7 +804,9 @@ int32_t mp_kms_keymap_copy(moonbit_bytes_t out) { MOONBIT_FFI_EXPORT void mp_kms_close(void) { - g_touch_active = 0; + touch_cancel(); + if (g_touch_timer >= 0) { close(g_touch_timer); g_touch_timer = -1; } + g_phys_w = 0; g_phys_h = 0; g_mm_w = 0; g_mm_h = 0; g_scale = 1; if (g_li) { libinput_unref(g_li); g_li = NULL; } if (g_udev) { udev_unref(g_udev); g_udev = NULL; } if (g_xkb_state) { xkb_state_unref(g_xkb_state); g_xkb_state = NULL; } diff --git a/compositor/shell/battery.mbt b/compositor/shell/battery.mbt index 5e3b637..7101b36 100644 --- a/compositor/shell/battery.mbt +++ b/compositor/shell/battery.mbt @@ -32,9 +32,12 @@ fn read_battery_polled() -> BatteryInfo { b } -///| Names Linux gives batteries (ACPI, Apple, Chromebooks, many ARM boards). The tree is not listed: +///| Names Linux gives batteries (ACPI, Apple, Qualcomm/ARM fuel gauges). The tree is not listed: /// a lookup of each name keeps this to plain file reads, which every host serves. -let battery_names : Array[String] = ["BAT0", "BAT1", "BAT2", "BATT", "BATC", "CMB0", "CMB1", "battery"] +let battery_names : Array[String] = [ + "BAT0", "BAT1", "BAT2", "BATT", "BATC", "CMB0", "CMB1", "battery", "bq27411-0", "qcom-battery", + "bms", "max170xx_battery", "axp20x-battery", "rk817-battery", +] ///| The `battery.status` record: state is the `charge-state` index (0 none, 1 discharging, /// 2 charging, 3 full, 4 not charging). diff --git a/compositor/shell/desktop_module.mbt b/compositor/shell/desktop_module.mbt index 28c664b..40e12e0 100644 --- a/compositor/shell/desktop_module.mbt +++ b/compositor/shell/desktop_module.mbt @@ -24,8 +24,25 @@ pub let wallpaper_desktop : String = "wallpaper" ///| pub let clock_card_desktop : String = "clock-card" -///| What fills a fresh session's desktop: the clock card, as before desktop modules. -let default_desktop : String = "clock-card" +///| +pub let icon_desktop : String = "icon-desktop" + +///| Default desktop choice for a fresh session: Icon Desktop on handsets (or +/// CHANDRA_DEFAULT_DESKTOP when set), otherwise the clock card. Tests keep the clock card. +pub fn default_desktop_id() -> String { + if @sys.getenv("CHANDRA_TEST_CONFIG") != "" { + return clock_card_desktop + } + let env = @sys.getenv("CHANDRA_DEFAULT_DESKTOP") + if env.length() > 0 { + return env + } + let info = @utf8.decode_lossy(@sys.read_file_bytes("/etc/machine-info")) + if info.contains("CHASSIS=handset") { + return icon_desktop + } + clock_card_desktop +} ///| A module's frame request is capped at this (ms): a module can't put itself to sleep for /// hours by mistake and miss its own animation. @@ -81,7 +98,7 @@ fn DesktopShell::write_desktop_choice(self : DesktopShell) -> Unit { _ => entries.push(e) } } - if self.desk_choice != default_desktop { + if self.desk_choice != default_desktop_id() { entries.push((@edn.Value::Keyword("desktop"), @edn.Value::Text(self.desk_choice))) } write_state_file(entries) diff --git a/compositor/shell/shell.mbt b/compositor/shell/shell.mbt index 3da0069..f9659ef 100644 --- a/compositor/shell/shell.mbt +++ b/compositor/shell/shell.mbt @@ -416,6 +416,8 @@ pub(all) struct DesktopShell { desk_saved : Map[String, String] /// The menu's top edge when it opens at the pointer (the desktop menu); -1 above the panel. mut menu_anchor_y : Int + /// Extra bottom inset reserved for panel popups (e.g. an open on-screen keyboard). + mut popup_bottom_inset : Int } ///| @@ -538,7 +540,7 @@ pub fn DesktopShell::new(display : String) -> DesktopShell { wit_cache: {}, recents: [], launcher_state: @launcher.State::new(), - desk_choice: default_desktop, + desk_choice: default_desktop_id(), desk_choice_read: false, desk_mod: None, desk_backdrop: 0, @@ -554,6 +556,7 @@ pub fn DesktopShell::new(display : String) -> DesktopShell { desk_covered: false, desk_saved: {}, menu_anchor_y: -1, + popup_bottom_inset: 0, } sh.order_apps() sh @@ -681,6 +684,37 @@ fn DesktopShell::open_popup_widget(self : DesktopShell) -> Widget? { None } +///| The module id of the currently open panel popup, or "" when none (or only the menu is open). +pub fn DesktopShell::open_popup_module_id(self : DesktopShell) -> String { + match self.open_popup_widget() { + Some(w) => w.module_id + None => "" + } +} + +///| The screen rectangle of the currently open panel popup, if any. +pub fn DesktopShell::open_popup_rect(self : DesktopShell) -> @scene.Rect? { + match self.open_popup_widget() { + Some(w) if w.popup_rect.w > 0 => Some(w.popup_rect) + _ => None + } +} + +///| Reserve extra room at the bottom for popups (e.g. an open on-screen keyboard) and +/// reposition any open popup above it. +pub fn DesktopShell::set_popup_bottom_inset(self : DesktopShell, inset : Int) -> Unit { + let v = if inset > 0 { inset } else { 0 } + if self.popup_bottom_inset == v { + return + } + self.popup_bottom_inset = v + for w in self.widgets.copy() { + if w.popup_rect.w > 0 { + self.refresh_popup(w) + } + } +} + ///| fn DesktopShell::widget_at(self : DesktopShell, x : Int, y : Int) -> Widget? { for w in self.widgets { diff --git a/compositor/shell/widgets.mbt b/compositor/shell/widgets.mbt index 3c289c4..c5ce0dd 100644 --- a/compositor/shell/widgets.mbt +++ b/compositor/shell/widgets.mbt @@ -34,6 +34,20 @@ fn fresh_panel(has_battery : Bool) -> Array[String] { out } +///| Compact default panel for handsets (omits desktop-only inspector, tiling toggle, and moon +/// disc so the dock, launcher, settings, Wi-Fi, battery, clock, and screenshot have room). +let handset_panel : Array[String] = [ + "launcher", "dock", "session-settings", "network", "battery", "clock-digital", "screenshot", +] + +///| Whether a fresh session runs on a handset chassis (tests keep the desktop layout). +fn is_handset_panel() -> Bool { + if @sys.getenv("CHANDRA_TEST_CONFIG") != "" { + return false + } + @utf8.decode_lossy(@sys.read_file_bytes("/etc/machine-info")).contains("CHASSIS=handset") +} + ///| test "a fresh panel gets the battery module only on a machine with a battery" { assert_false(fresh_panel(false).contains("battery")) @@ -189,12 +203,23 @@ fn DesktopShell::panel_slots(self : DesktopShell) -> Array[@panel.SlotIn] { first_stretch = i } } + let compact = self.screen_w > 0 && self.screen_w < 720 let out : Array[@panel.SlotIn] = [] for i = 0; i < self.widgets.length(); i = i + 1 { let w = self.widgets[i] + let base_w = self.dock_width(w).unwrap_or(w.pl.pref_w) + let pref_w = if compact && + (w.module_id == "launcher" || + w.module_id == "session-settings" || + w.module_id == "network" || + w.module_id == "screenshot") { + 36 + } else { + base_w + } out.push({ id: w.slot, - pref_w: self.dock_width(w).unwrap_or(w.pl.pref_w), + pref_w, pref_h: w.pl.pref_h, min_w: w.pl.min_w, stretch: w.pl.stretch, @@ -337,7 +362,12 @@ fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit { let saved = self.load_panel_config() let entries = match saved { Some(e) => migrate_panel(e) - None => fresh_panel(read_battery().state != 0) + None => + if is_handset_panel() { + handset_panel + } else { + fresh_panel(read_battery().state != 0) + } } match saved { Some(old) if saved_panel_version() < panel_version => { @@ -972,7 +1002,12 @@ fn DesktopShell::refresh_popup(self : DesktopShell, w : Widget) -> Unit { w.popup_hot = false } Some(ps) => { - let (px, py) = @panel.popup_position(self.screen_w, self.screen_h - self.panel_h, w.rect.x, ps.w, ps.h, 6) + let bottom = if self.popup_bottom_inset > self.panel_h { + self.popup_bottom_inset + } else { + self.panel_h + } + let (px, py) = @panel.popup_position(self.screen_w, self.screen_h - bottom, w.rect.x, ps.w, ps.h, 6) w.popup_rect = { x: px, y: py, w: ps.w, h: ps.h } w.popup_ops = ps.ops if !was_open { diff --git a/lib/battery/battery.mbt b/lib/battery/battery.mbt index 2e94425..b309210 100644 --- a/lib/battery/battery.mbt +++ b/lib/battery/battery.mbt @@ -38,7 +38,7 @@ pub let critical_percent : Int = 10 ///| pub fn info() -> (String, String, Int, Int, Int) { // id, name, preferred w, preferred h, min w - ("org.chandra.battery", "Battery", 104, 34, 34) + ("org.chandra.battery", "Battery", 76, 34, 34) } ///| diff --git a/lib/clock/clock.mbt b/lib/clock/clock.mbt index c6b0b15..3664d22 100644 --- a/lib/clock/clock.mbt +++ b/lib/clock/clock.mbt @@ -3,7 +3,7 @@ ///| pub fn digital_info() -> (String, String, Int, Int, Int) { // id, name, preferred w, preferred h, min w - ("org.chandra.clock.digital", "Digital Clock", 120, 36, 80) + ("org.chandra.clock.digital", "Digital Clock", 96, 36, 80) } ///| diff --git a/lib/launcher/launcher.mbt b/lib/launcher/launcher.mbt index ade8c87..b8562ec 100644 --- a/lib/launcher/launcher.mbt +++ b/lib/launcher/launcher.mbt @@ -190,7 +190,7 @@ pub fn close(st : State) -> Unit { st.armed = -1 } -///| The panel button: a crescent moon plus a label. +///| The panel button: a crescent moon plus a label (shortens to "Apps" or icon-only when tight). pub fn render_button( size : @types.Size, t : @theme.Tokens, @@ -201,14 +201,24 @@ pub fn render_button( let bg = if st.open { t.palette.accent } else { t.palette.surface_hover } let fg = if st.open { t.palette.accent_foreground } else { t.palette.foreground } let r = t.radius.reinterpret_as_int() + let fs = t.font_size.reinterpret_as_int() let cy = h / 2 - [ - @ui.fill_rect(@ui.rect(0, 0, w, h), bg, radius=r), + let ops = [@ui.fill_rect(@ui.rect(0, 0, w, h), bg, radius=r)] + if 36 + @ui.text_width("Applications", fs) + 12 <= w { // Crescent: light disc with a button-coloured disc biting into it. - @ui.circle(18, cy, 9, fg), - @ui.circle(22, cy - 3, 8, bg), - @ui.text(36, cy, "Applications", t.font_size.reinterpret_as_int(), fg, bold=true), - ] + ops.push(@ui.circle(18, cy, 9, fg)) + ops.push(@ui.circle(22, cy - 3, 8, bg)) + ops.push(@ui.text(36, cy, "Applications", fs, fg, bold=true)) + } else if 34 + @ui.text_width("Apps", fs) + 10 <= w { + ops.push(@ui.circle(17, cy, 9, fg)) + ops.push(@ui.circle(21, cy - 3, 8, bg)) + ops.push(@ui.text(34, cy, "Apps", fs, fg, bold=true)) + } else { + let cx = w / 2 + ops.push(@ui.circle(cx, cy, 9, fg)) + ops.push(@ui.circle(cx + 4, cy - 3, 8, bg)) + } + ops } ///| diff --git a/session/chandra-ctl b/session/chandra-ctl index 91ec492..3587d1f 100755 --- a/session/chandra-ctl +++ b/session/chandra-ctl @@ -9,6 +9,7 @@ chandra-ctl kiosk [lock|unlock|status] kiosk mode (--kiosk, docs/kiosk.md) chandra-ctl launch ID start desktop app ID (org.kde.kwi) as the dock does chandra-ctl windows how Chandra sees each window, and what is under the pointer + chandra-ctl screenshot [PATH] save a full-screen PNG directly without opening the editor chandra-ctl auth-demo [MODE] show the password dialog with a pretend check (password "demo"); MODE: password, face, face-ok, die, slow, users (docs/auth-dialog.md) chandra-ctl auth-status the password dialog's agent: registered with polkit, or why not @@ -24,7 +25,7 @@ import os import socket import sys -USAGE = "usage: chandra-ctl [--socket PATH] [--quiet] {reload [NAME] | list | ping | shortcut ID | kiosk [lock|unlock|status] | launch ID | windows | auth-demo [MODE] | auth-status | help}" +USAGE = "usage: chandra-ctl [--socket PATH] [--quiet] {reload [NAME] | list | ping | shortcut ID | kiosk [lock|unlock|status] | launch ID | windows | screenshot [PATH] | auth-demo [MODE] | auth-status | help}" def runtime_dir(): diff --git a/session/chandra-session b/session/chandra-session index bbfd222..f030208 100755 --- a/session/chandra-session +++ b/session/chandra-session @@ -193,6 +193,13 @@ export CHANDRA_SESSION_ERRORS="$session_errors" if command -v gnome-keyring-daemon >/dev/null 2>&1; then eval "$(gnome-keyring-daemon --start --components=secrets 2>>"$log")" [ -n "$SSH_AUTH_SOCK" ] && export SSH_AUTH_SOCK + if command -v busctl >/dev/null 2>&1 && + [ -f "$HOME/.local/share/keyrings/login.keyring" ] && + grep -q '^\[keyring\]' "$HOME/.local/share/keyrings/login.keyring" 2>/dev/null; then + busctl --user call org.freedesktop.secrets /org/freedesktop/secrets \ + org.freedesktop.Secret.Service Unlock ao 1 \ + /org/freedesktop/secrets/aliases/default >/dev/null 2>&1 || true + fi fi # A logind session without a seat (made by run0 --user=..., su - or ssh rather than by logging in diff --git a/wasmhost/bin/display.mbt b/wasmhost/bin/display.mbt index 5d6209d..ddf4869 100644 --- a/wasmhost/bin/display.mbt +++ b/wasmhost/bin/display.mbt @@ -54,7 +54,7 @@ extern "C" fn rs_present_kms() = "rs_present_kms" ///| The seat, DRM and input fds while the display is open (none otherwise), for an idle wait. fn display_wait_fds() -> Array[Int] { let out : Array[Int] = [] - for i in 0..<3 { + for i in 0..<4 { let fd = mp_kms_fd(i) if fd >= 0 { out.push(fd)