S056 (WIP): real PiP (video only, floating, own app id), Material PiP controls, side buttons, middle/Ctrl-click links in a new tab, spell underline position
Resume: freeze not reproduced yet (hidden + visible); context menu works on a test page, YouTube case waits for the orchestrator's answer; bindings audit list, final smokes, PROGRESS. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
parent
3ffe0cbebd
commit
0478385bcb
10 changed files with 308 additions and 67 deletions
|
|
@ -2347,8 +2347,8 @@ impl App {
|
|||
};
|
||||
let Some((w, i)) = app.find_tab(tab_id) else { return };
|
||||
let Some(view) = app.windows[&w].tabs[i].web.as_ref().map(|web| web.webview.clone()) else { return };
|
||||
let width = 480u32;
|
||||
let height = ((width as f64) * vh.max(9.0) / vw.max(16.0)).round().clamp(120.0, 900.0) as u32;
|
||||
let width = app.shared.settings.borrow().window.pip_width.clamp(200, 1600);
|
||||
let height = pip_height(width, vw, vh);
|
||||
let win = app.windows.get_mut(&w).expect("found");
|
||||
win.tabs[i].pip_size = Some([width, height]);
|
||||
win.detach(&view);
|
||||
|
|
@ -2356,8 +2356,10 @@ impl App {
|
|||
if let Some(pip) = app.open_window(Kind::Pip { window: w, tab: tab_id }, Vec::new(), 0, Some((width, height)))
|
||||
&& let Some(win) = app.windows.get_mut(&pip)
|
||||
{
|
||||
win.pip_view = Some(view);
|
||||
win.pip_view = Some(view.clone());
|
||||
win.sync_webviews();
|
||||
// Only the video now: it goes full screen inside this window (see `Event::Fullscreen`).
|
||||
view.evaluate_javascript(inject::call("pip.full", &[]), |_| {});
|
||||
}
|
||||
app.redraw(w);
|
||||
}));
|
||||
|
|
@ -2369,12 +2371,18 @@ impl App {
|
|||
pub fn exit_pip(&mut self, source: WindowId, tab_id: u64) {
|
||||
let pip = self.windows.iter_mut().find(|(_, w)| matches!(w.kind, Kind::Pip { tab, .. } if tab == tab_id)).and_then(|(_, w)| w.pip_view.take().map(|v| (v, w)));
|
||||
if let Some((view, pip)) = pip {
|
||||
let width = pip.size().0;
|
||||
if width >= 200 {
|
||||
self.shared.settings.borrow_mut().window.pip_width = width;
|
||||
}
|
||||
pip.detach(&view);
|
||||
view.evaluate_javascript(inject::call("pip.leave", &[]), |_| {});
|
||||
}
|
||||
let Some(win) = self.windows.get_mut(&source) else { return };
|
||||
let Some(i) = win.tab_index(tab_id) else { return };
|
||||
win.tabs[i].pip_size = None;
|
||||
// The page leaves its full screen too; that news then belongs to nobody.
|
||||
win.tabs[i].fullscreen = false;
|
||||
win.sync_webviews();
|
||||
self.redraw(source);
|
||||
}
|
||||
|
|
@ -2547,9 +2555,24 @@ fn fmt_count(n: usize) -> String {
|
|||
out
|
||||
}
|
||||
|
||||
/// The picture-in-picture window's height for a width: the video's aspect ratio (16:9 when the page didn't say).
|
||||
fn pip_height(width: u32, video_w: f64, video_h: f64) -> u32 {
|
||||
let (vw, vh) = if video_w >= 1.0 && video_h >= 1.0 { (video_w, video_h) } else { (16.0, 9.0) };
|
||||
((width as f64) * vh / vw).round().clamp(120.0, 1200.0) as u32
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::step_match;
|
||||
use super::{pip_height, step_match};
|
||||
|
||||
#[test]
|
||||
fn pip_window_follows_the_video_aspect() {
|
||||
assert_eq!(pip_height(480, 1920.0, 1080.0), 270);
|
||||
assert_eq!(pip_height(480, 1080.0, 1920.0), 853);
|
||||
// No size from the page yet: 16:9.
|
||||
assert_eq!(pip_height(480, 0.0, 0.0), 270);
|
||||
assert_eq!(pip_height(200, 4000.0, 100.0), 120);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_steps_wrap_around() {
|
||||
|
|
@ -2560,3 +2583,4 @@ mod tests {
|
|||
assert_eq!(step_match(0, 0, true), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
50
src/app.rs
50
src/app.rs
|
|
@ -722,6 +722,20 @@ impl App {
|
|||
if let Some((w, i)) = self.find_webview(id)
|
||||
&& let Some(win) = self.windows.get_mut(&w)
|
||||
{
|
||||
let tab = &mut win.tabs[i];
|
||||
// In picture in picture the video's full screen stays inside the PiP window; the page leaving it
|
||||
// (its own button, Escape) ends picture in picture.
|
||||
if tab.pip_size.is_some() {
|
||||
let (was, tab_id) = (std::mem::replace(&mut tab.fullscreen, on), tab.id);
|
||||
if was && !on {
|
||||
self.run(Command::ClosePip(tab_id));
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Picture in picture already ended (`exit_pip`): nothing to undo here.
|
||||
if !on && !tab.fullscreen {
|
||||
return;
|
||||
}
|
||||
win.tabs[i].fullscreen = on;
|
||||
win.fullscreen = on;
|
||||
if on { win.window.fullscreen() } else { win.window.unfullscreen() }
|
||||
|
|
@ -755,6 +769,12 @@ impl App {
|
|||
self.redraw(w);
|
||||
},
|
||||
Event::CreateNew(parent, view, url) => self.on_create_new(parent, view, url),
|
||||
Event::OpenLink(id, url, front) => {
|
||||
if let Some((w, i)) = self.find_webview(id) {
|
||||
let from = Some(self.windows[&w].tabs[i].id);
|
||||
self.run_in(w, Command::Open { url: url.to_string(), how: if front { Disposition::NewForegroundTab } else { Disposition::NewBackgroundTab }, from });
|
||||
}
|
||||
},
|
||||
Event::Permission(id, kind, request) => self.on_permission(id, kind, request),
|
||||
Event::Auth(id, request) => {
|
||||
let origin = request.origin();
|
||||
|
|
@ -1236,6 +1256,14 @@ impl App {
|
|||
let me = self.me.clone();
|
||||
let busy = Box::new(move || me.upgrade().is_some_and(|app| app.try_borrow_mut().is_err()));
|
||||
let mut win = BrowserWindow::create(&self.gtk, id, kind.clone(), &title, size, decorated, ui, busy);
|
||||
if let Kind::Pip { window: source, .. } = &kind
|
||||
&& let Some(parent) = self.windows.get(source)
|
||||
{
|
||||
// A window with a parent floats on tiling compositors (niri) without a user rule; its own app id lets a
|
||||
// rule still pick it out.
|
||||
win.window.set_transient_for(Some(&parent.window));
|
||||
crate::window::set_app_id(&win.window, "dev.nacre.Nacre.Pip");
|
||||
}
|
||||
if settings.window.maximized && kind == Kind::Normal && self.windows.is_empty() {
|
||||
win.window.maximize();
|
||||
}
|
||||
|
|
@ -1317,6 +1345,28 @@ impl App {
|
|||
glib::Propagation::Stop
|
||||
});
|
||||
win.window.add_controller(scroll);
|
||||
// Mouse back/forward buttons (8/9) navigate over the page and the chrome; WebKit has no use for them.
|
||||
let sides = gtk::GestureClick::new();
|
||||
sides.set_button(0);
|
||||
sides.set_propagation_phase(gtk::PropagationPhase::Capture);
|
||||
let me = self.me.clone();
|
||||
sides.connect_pressed(move |g, _, _, _| {
|
||||
let back = match g.current_button() {
|
||||
8 => true,
|
||||
9 => false,
|
||||
_ => return,
|
||||
};
|
||||
g.set_state(gtk::EventSequenceState::Claimed);
|
||||
if let Some(app) = me.upgrade() {
|
||||
with_app(&app, move |app| {
|
||||
let blocked = app.windows.get(&id).is_some_and(|w| w.tab().is_some_and(|t| t.dialog.is_some()) || w.ui.blocks_page());
|
||||
if !blocked {
|
||||
app.run_in(id, if back { Command::Back } else { Command::Forward });
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
win.window.add_controller(sides);
|
||||
}
|
||||
|
||||
/// A key press anywhere in the window, before the focused widget sees it. True: it was a browser shortcut.
|
||||
|
|
|
|||
|
|
@ -611,9 +611,22 @@ impl Engine {
|
|||
let filters = self.filters.clone();
|
||||
let images = self.images_filter.clone();
|
||||
web.connect_decide_policy(move |web, decision, kind| match kind {
|
||||
webkit::PolicyDecisionType::NavigationAction => {
|
||||
webkit::PolicyDecisionType::NavigationAction | webkit::PolicyDecisionType::NewWindowAction => {
|
||||
let Some(nav) = decision.downcast_ref::<webkit::NavigationPolicyDecision>() else { return false };
|
||||
let Some(mut action) = nav.navigation_action() else { return false };
|
||||
// A link clicked with the middle button or Ctrl opens in a new tab (Ctrl+Shift: in front), as in
|
||||
// other browsers; WebKit would load it here.
|
||||
let mods = gtk::gdk::ModifierType::from_bits_truncate(action.modifiers());
|
||||
if action.navigation_type() == webkit::NavigationType::LinkClicked && (action.mouse_button() == 2 || mods.contains(gtk::gdk::ModifierType::CONTROL_MASK))
|
||||
&& let Some(url) = action.request().and_then(|r| r.uri()).and_then(|u| Url::parse(&u).ok())
|
||||
{
|
||||
decision.ignore();
|
||||
hub.push(Event::OpenLink(id, url, mods.contains(gtk::gdk::ModifierType::SHIFT_MASK)));
|
||||
return true;
|
||||
}
|
||||
if kind == webkit::PolicyDecisionType::NewWindowAction {
|
||||
return false;
|
||||
}
|
||||
// Only the top frame: frames load as the page asks.
|
||||
if action.frame_name().is_some() {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -78,6 +78,8 @@ pub enum Event {
|
|||
/// A pop-up (`window.open`, target=_blank): its view, already made as a related view of the opener, and the
|
||||
/// address it will load (none for `about:blank`-style opens).
|
||||
CreateNew(ViewId, View, Option<Url>),
|
||||
/// A link clicked with the middle button or Ctrl: open it in a new tab (true: in front).
|
||||
OpenLink(ViewId, Url, bool),
|
||||
Permission(ViewId, crate::store::permissions::Kind, PermissionAsk),
|
||||
Auth(ViewId, AuthRequest),
|
||||
Control(ViewId, Control),
|
||||
|
|
|
|||
|
|
@ -235,8 +235,9 @@ const MEDIA_JS: &str = r#"(() => { if (!window.__nacre || window.__nacre.media)
|
|||
} };
|
||||
})();"#;
|
||||
|
||||
/// Picture-in-picture. The tab's own view moves into the PiP window (no reload, page state kept); `enter` makes its
|
||||
/// biggest (playing) video fill the viewport, `leave` puts the page back as it was.
|
||||
/// Picture-in-picture. The tab's own view moves into the PiP window (no reload, page state kept); `enter` picks its
|
||||
/// biggest (playing) video, `full` shows only that video (a style that makes it fill the viewport, its parent in full
|
||||
/// screen), `leave` puts the page back.
|
||||
const PIP_JS: &str = r#"(() => { if (!window.__nacre || window.__nacre.pip) return;
|
||||
const pick = () => {
|
||||
const vs = [...document.querySelectorAll('video')].filter(v => v.readyState > 0);
|
||||
|
|
@ -247,18 +248,28 @@ const PIP_JS: &str = r#"(() => { if (!window.__nacre || window.__nacre.pip) retu
|
|||
enter() {
|
||||
const v = pick();
|
||||
if (!v) return null;
|
||||
window.__nacrePipV = v; v.setAttribute('data-nacre-pip', '');
|
||||
if (!document.getElementById('__nacre_pip_css')) {
|
||||
const st = document.createElement('style'); st.id = '__nacre_pip_css';
|
||||
st.textContent = 'video[data-nacre-pip]{position:fixed!important;inset:0!important;margin:0!important;width:100vw!important;height:100vh!important;' +
|
||||
'max-width:none!important;max-height:none!important;object-fit:contain!important;background:#000!important;z-index:2147483647!important;transform:none!important}' +
|
||||
'html.__nacre_pip,html.__nacre_pip body{overflow:hidden!important}';
|
||||
(document.head || document.documentElement).appendChild(st);
|
||||
}
|
||||
document.documentElement.classList.add('__nacre_pip');
|
||||
window.__nacrePipV = v;
|
||||
return { w: v.videoWidth || 16, h: v.videoHeight || 9, paused: v.paused };
|
||||
},
|
||||
full() {
|
||||
const v = window.__nacrePipV;
|
||||
if (!v) return;
|
||||
// The video fills the viewport (its own style), and its parent goes full screen, so nothing of the page shows
|
||||
// and the page's transforms can't move the video. Not the video itself: WebKit's video full screen mode stops
|
||||
// playback in a GTK host. The browser keeps that full screen inside the PiP window.
|
||||
const st = document.getElementById('__nacre_pip_css') || document.createElement('style'); st.id = '__nacre_pip_css';
|
||||
st.textContent = 'video[data-nacre-pip]{position:fixed!important;inset:0!important;margin:0!important;width:100vw!important;height:100vh!important;' +
|
||||
'max-width:none!important;max-height:none!important;object-fit:contain!important;background:#000!important;z-index:2147483647!important;transform:none!important}' +
|
||||
'video[data-nacre-pip]::-webkit-media-controls{display:none!important}' +
|
||||
'html.__nacre_pip,html.__nacre_pip body{overflow:hidden!important}';
|
||||
(document.head || document.documentElement).appendChild(st);
|
||||
v.setAttribute('data-nacre-pip', '');
|
||||
document.documentElement.classList.add('__nacre_pip');
|
||||
const box = v.parentElement || document.documentElement;
|
||||
try { const p = (box.requestFullscreen || box.webkitRequestFullscreen).call(box); if (p && p.catch) p.catch(() => {}); } catch (e) {}
|
||||
},
|
||||
leave() { const v = window.__nacrePipV; window.__nacrePipV = null;
|
||||
if (document.fullscreenElement || document.webkitFullscreenElement) (document.exitFullscreen || document.webkitExitFullscreen).call(document);
|
||||
if (v) v.removeAttribute('data-nacre-pip');
|
||||
document.documentElement.classList.remove('__nacre_pip'); },
|
||||
state() { const v = window.__nacrePipV; if (!v || !v.isConnected) return null;
|
||||
|
|
@ -584,7 +595,7 @@ const AUTOFILL_JS: &str = r#"(() => { if (!window.__nacre || window.__nacre.fill
|
|||
/// wavy underline drawn in an overlay that mirrors the field.
|
||||
const SPELL_JS: &str = r#"(() => { if (!window.__nacre || window.__nacre.spell) return;
|
||||
const css = () => { if (document.getElementById('__nacre_spell_css')) return; const s = document.createElement('style'); s.id = '__nacre_spell_css';
|
||||
s.textContent = '.__nacre_spell_mirror{position:absolute;pointer-events:none;color:transparent!important;overflow:hidden;white-space:pre-wrap;word-wrap:break-word;z-index:2147483646}' +
|
||||
s.textContent = '.__nacre_spell_mirror{position:fixed;margin:0;pointer-events:none;color:transparent!important;overflow:hidden;white-space:pre-wrap;word-wrap:break-word;z-index:2147483646}' +
|
||||
'.__nacre_spell_mirror u{text-decoration:underline wavy #e53935;text-decoration-skip-ink:none;color:transparent}';
|
||||
(document.head || document.documentElement).appendChild(s); };
|
||||
let field = null, mirror = null, timer = 0, bad = new Set();
|
||||
|
|
@ -592,10 +603,15 @@ const SPELL_JS: &str = r#"(() => { if (!window.__nacre || window.__nacre.spell)
|
|||
const words = t => (t.match(/[\p{L}][\p{L}'’]*/gu) || []).slice(0, 400);
|
||||
const esc = s => s.replace(/[&<>]/g, c => ({ '&': '&', '<': '<', '>': '>' }[c]));
|
||||
const draw = () => { if (!field || !mirror) return; const st = getComputedStyle(field), r = field.getBoundingClientRect();
|
||||
for (const p of ['font', 'letterSpacing', 'lineHeight', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'borderTopWidth', 'borderLeftWidth', 'textAlign', 'textIndent', 'wordSpacing', 'boxSizing']) mirror.style[p] = st[p];
|
||||
for (const p of ['font', 'letterSpacing', 'lineHeight', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', 'textAlign', 'textIndent', 'wordSpacing']) mirror.style[p] = st[p];
|
||||
mirror.style.boxSizing = 'border-box';
|
||||
mirror.style.borderStyle = 'solid'; mirror.style.borderColor = 'transparent';
|
||||
Object.assign(mirror.style, { left: (r.left + scrollX) + 'px', top: (r.top + scrollY) + 'px', width: r.width + 'px', height: r.height + 'px' });
|
||||
if (field.tagName === 'INPUT') mirror.style.whiteSpace = 'pre';
|
||||
// Fixed at the field's viewport box: absolute would be off wherever the body is positioned or transformed.
|
||||
Object.assign(mirror.style, { left: r.left + 'px', top: r.top + 'px', width: r.width + 'px', height: r.height + 'px' });
|
||||
// An input centres its one line vertically: the mirror's line fills the content box to match.
|
||||
if (field.tagName === 'INPUT') { mirror.style.whiteSpace = 'pre';
|
||||
const inner = r.height - parseFloat(st.paddingTop) - parseFloat(st.paddingBottom) - parseFloat(st.borderTopWidth) - parseFloat(st.borderBottomWidth);
|
||||
mirror.style.lineHeight = Math.max(0, inner) + 'px'; }
|
||||
mirror.innerHTML = esc(field.value).replace(/[\p{L}][\p{L}'’]*/gu, w => bad.has(w) ? '<u>' + w + '</u>' : w);
|
||||
mirror.scrollTop = field.scrollTop; mirror.scrollLeft = field.scrollLeft; };
|
||||
const check = () => { timer = 0; if (!field) return; __send('spell', [...new Set(words(field.value))]); };
|
||||
|
|
@ -605,6 +621,7 @@ const SPELL_JS: &str = r#"(() => { if (!window.__nacre || window.__nacre.spell)
|
|||
document.addEventListener('focusout', e => { if (e.target === field) { field = null; if (mirror) mirror.remove(); } }, true);
|
||||
document.addEventListener('input', e => { if (e.target !== field) return; draw(); if (!timer) timer = setTimeout(check, 400); }, true);
|
||||
document.addEventListener('scroll', () => draw(), true);
|
||||
addEventListener('resize', () => draw());
|
||||
window.__nacre.spell = {
|
||||
mark(list) { bad = new Set(list || []); draw(); },
|
||||
replace(word, by) { const el = field || document.activeElement; if (!el || !('value' in el)) return;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
//! type <text> put text in the address bar with its suggestions open
|
||||
//! fakeload <seconds>|done hold the active tab that far into a load, or end it
|
||||
//! blur leave the address field (as Escape does)
|
||||
//! hover <x> <y>|none move the pointer over the window (points), or away
|
||||
//! hover <x> <y> [pip]|none move the pointer over the window (points; `pip`: the picture-in-picture window), or away
|
||||
//! do <action> a shortcut action by its settings key, e.g. `do new_tab`
|
||||
//! cmd <name> [arg] back, forward, reload, bookmark, install_app, pip, exitpip, free_memory,
|
||||
//! update_lists, check_updates, close_tab, select <n>, zoom <step>,
|
||||
|
|
@ -37,6 +37,7 @@
|
|||
//! the right button (context menu). With NACRE_WL_INPUT (tools/wl-input, hidden runs of
|
||||
//! tools/smoke.sh) `click`, `rclick`, `pagescroll` and `pagetype` are real compositor input
|
||||
//! (wl-input pointer, wtype keyboard); without it they are synthesized in the page (no rclick)
|
||||
//! mclick|backclick|fwdclick <x> <y> the same with the middle / back (8) / forward (9) button; real input only
|
||||
//! locate <css selector> find the first visible matching element, scroll it into view; `click @` / `rclick @` then click its centre
|
||||
//! pagescroll <x> <y> <dy> turn the wheel over the page at x,y (as `click`) by dy pixels (positive: down)
|
||||
//! pagetype <text> type text into the page, if it has keyboard focus (after a `click` in a field);
|
||||
|
|
@ -573,7 +574,7 @@ impl App {
|
|||
}
|
||||
});
|
||||
},
|
||||
"click" | "rclick" => {
|
||||
"click" | "rclick" | "mclick" | "backclick" | "fwdclick" => {
|
||||
// Through the window's real input path (pointer over UI, dialogs, focus), as a user's click would.
|
||||
// `click @` clicks where the last `locate` found its element.
|
||||
let located = if rest.trim() == "@" { self.selftest.as_ref().and_then(|t| t.located.lock().ok().and_then(|l| *l)) } else { None };
|
||||
|
|
@ -586,7 +587,13 @@ impl App {
|
|||
// Hidden runs click with the compositor's pointer (wl-input), so the page gets real GTK input; elsewhere
|
||||
// (SMOKE_VISIBLE, never the user's pointer) the click is synthesized in the page's DOM.
|
||||
if WL_INPUT.is_some() && let Some((ox, oy)) = self.selftest_output_point(window, x, y) {
|
||||
let button = if verb == "rclick" { "right" } else { "left" };
|
||||
let button = match verb {
|
||||
"rclick" => "right",
|
||||
"mclick" => "middle",
|
||||
"backclick" => "side",
|
||||
"fwdclick" => "extra",
|
||||
_ => "left",
|
||||
};
|
||||
self.selftest_wl_input(&["click".into(), ox.to_string(), oy.to_string(), button.into()]);
|
||||
return;
|
||||
}
|
||||
|
|
@ -598,7 +605,7 @@ impl App {
|
|||
win.focus_page();
|
||||
}
|
||||
},
|
||||
Some(_) => self.selftest_log("rclick: needs real input (a hidden run)"),
|
||||
Some(_) => self.selftest_log(&format!("{verb}: needs real input (a hidden run)")),
|
||||
None => self.selftest_log("click: no web page in this tab"),
|
||||
}
|
||||
},
|
||||
|
|
@ -758,6 +765,8 @@ impl App {
|
|||
},
|
||||
"hover" => {
|
||||
// Put the pointer over the chrome (window points), or take it away with `hover none`.
|
||||
// `hover x y pip`: over the picture-in-picture window.
|
||||
let window = if rest.split_whitespace().nth(2) == Some("pip") { self.windows.iter().find(|(_, w)| matches!(w.kind, Kind::Pip { .. })).map_or(window, |(id, _)| *id) } else { window };
|
||||
let mut parts = rest.split_whitespace().filter_map(|p| p.parse::<f32>().ok());
|
||||
let event = match (parts.next(), parts.next()) {
|
||||
(Some(x), Some(y)) => egui::Event::PointerMoved(egui::pos2(x, y)),
|
||||
|
|
|
|||
|
|
@ -498,11 +498,13 @@ pub struct WindowState {
|
|||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub maximized: bool,
|
||||
/// Width of the picture-in-picture window (its height follows the video).
|
||||
pub pip_width: u32,
|
||||
}
|
||||
|
||||
impl Default for WindowState {
|
||||
fn default() -> Self {
|
||||
Self { width: 1280, height: 820, maximized: false }
|
||||
Self { width: 1280, height: 820, maximized: false, pip_width: 480 }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ use crate::tabs::Page;
|
|||
use crate::theme::{self, Palette, Weight};
|
||||
use crate::ui::icons;
|
||||
use crate::util;
|
||||
use crate::window::Kind;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum SuggestionKind {
|
||||
|
|
@ -1074,7 +1075,8 @@ pub fn pip_window(root: &mut Ui, f: &mut Frame) {
|
|||
// The tab's own view fills the window under this overlay; egui takes the pointer everywhere (no page rect).
|
||||
let rect = root.max_rect();
|
||||
let hovered = root.ctx().input(|i| i.pointer.hover_pos().is_some());
|
||||
if !hovered {
|
||||
let shown = theme::effect(root.ctx(), root.id().with("pip-shown"), hovered);
|
||||
if shown <= 0.0 {
|
||||
return;
|
||||
}
|
||||
let response = root.interact(rect, root.id().with("pip-surface"), Sense::click_and_drag());
|
||||
|
|
@ -1086,27 +1088,39 @@ pub fn pip_window(root: &mut Ui, f: &mut Frame) {
|
|||
} else if response.clicked() {
|
||||
f.send(Command::PipAct { action: "toggle".into(), value: 0.0 });
|
||||
}
|
||||
egui::Area::new(egui::Id::new("pip-controls")).anchor(egui::Align2::CENTER_BOTTOM, egui::vec2(0.0, -8.0)).show(root.ctx(), |ui| {
|
||||
egui::Frame::popup(ui.style()).fill(Color32::from_black_alpha(170)).show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let white = |t: &str| RichText::new(t).color(Color32::WHITE).size(16.0);
|
||||
if ui.add(egui::Button::new(white(icons::FAST_REWIND)).frame(false)).on_hover_text("Back 10 seconds").clicked() {
|
||||
f.send(Command::PipAct { action: "skip".into(), value: -10.0 });
|
||||
}
|
||||
if ui.add(egui::Button::new(white(icons::PLAY_PAUSE)).frame(false)).on_hover_text("Play or pause").clicked() {
|
||||
f.send(Command::PipAct { action: "toggle".into(), value: 0.0 });
|
||||
}
|
||||
if ui.add(egui::Button::new(white(icons::FAST_FORWARD)).frame(false)).on_hover_text("Forward 10 seconds").clicked() {
|
||||
f.send(Command::PipAct { action: "skip".into(), value: 10.0 });
|
||||
}
|
||||
if ui.add(egui::Button::new(white(icons::VOLUME_OFF)).frame(false)).on_hover_text("Mute").clicked() {
|
||||
f.send(Command::PipAct { action: "mute".into(), value: 0.0 });
|
||||
}
|
||||
if ui.add(egui::Button::new(white(icons::PIP_EXIT)).frame(false)).on_hover_text("Back to the tab").clicked() {
|
||||
f.send(Command::ExitPip);
|
||||
}
|
||||
// The controls: a pill on the surface colour, Material icon buttons round the big play button, fading in while
|
||||
// the pointer is over the window.
|
||||
let p = f.palette();
|
||||
let now = f.shared.media_now.borrow().clone().filter(|n| matches!(f.kind, Kind::Pip { tab, .. } if *tab == n.tab));
|
||||
let playing = now.as_ref().is_some_and(|n| !n.state.paused);
|
||||
let muted = now.as_ref().is_some_and(|n| n.muted);
|
||||
egui::Area::new(egui::Id::new("pip-controls")).anchor(egui::Align2::CENTER_BOTTOM, egui::vec2(0.0, -12.0)).show(root.ctx(), |ui| {
|
||||
ui.set_opacity(shown);
|
||||
egui::Frame::new()
|
||||
.fill(p.surface_container_high)
|
||||
.corner_radius(theme::corner_radius(theme::FULL))
|
||||
.inner_margin(egui::Margin::symmetric(10, 6))
|
||||
.shadow(egui::Shadow { offset: [0, 3], blur: 14, spread: 0, color: Color32::from_black_alpha(if p.dark { 110 } else { 46 }) })
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal_centered(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 6.0;
|
||||
if icon_button(ui, icons::FAST_REWIND, "Back 10 seconds").clicked() {
|
||||
f.send(Command::PipAct { action: "skip".into(), value: -10.0 });
|
||||
}
|
||||
if menus::play_button(ui, playing).clicked() {
|
||||
f.send(Command::PipAct { action: "toggle".into(), value: 0.0 });
|
||||
}
|
||||
if icon_button(ui, icons::FAST_FORWARD, "Forward 10 seconds").clicked() {
|
||||
f.send(Command::PipAct { action: "skip".into(), value: 10.0 });
|
||||
}
|
||||
if icon_toggle(ui, if muted { icons::VOLUME_OFF } else { icons::VOLUME_UP }, if muted { "Unmute" } else { "Mute" }, muted).clicked() {
|
||||
f.send(Command::PipAct { action: "mute".into(), value: 0.0 });
|
||||
}
|
||||
if icon_button(ui, icons::PIP_EXIT, "Back to the tab").clicked() {
|
||||
f.send(Command::ExitPip);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ pub mod widgets;
|
|||
|
||||
use std::rc::Rc;
|
||||
|
||||
use egui::{Align2, Color32, RichText};
|
||||
use egui::{Align2, Color32};
|
||||
|
||||
use crate::actions::Command;
|
||||
use crate::app::Shared;
|
||||
|
|
@ -251,16 +251,11 @@ fn page_contents(ui: &mut egui::Ui, f: &mut Frame) {
|
|||
}
|
||||
if tab.pip_size.is_some() {
|
||||
*f.page_rect = None;
|
||||
ui.centered_and_justified(|ui| {
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.add_space(rect.height() * 0.35);
|
||||
ui.label(RichText::new("Playing in picture in picture").size(18.0));
|
||||
if ui.button("Bring it back").clicked() {
|
||||
let tab_id = f.tabs[*f.active].id;
|
||||
f.send(Command::ClosePip(tab_id));
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.add_space(rect.height() * 0.2);
|
||||
if widgets::empty_state(ui, icons::PICTURE_IN_PICTURE_ALT, "Playing in picture in picture", "The video plays in its own small window. Bring it back to see the whole page here again.", Some((icons::PIP_EXIT, "Bring it back"))) {
|
||||
let tab_id = f.tabs[*f.active].id;
|
||||
f.send(Command::ClosePip(tab_id));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let Some(reason) = tab.crashed.clone() {
|
||||
|
|
|
|||
|
|
@ -251,3 +251,20 @@ pub fn save_shot(window: >k::ApplicationWindow, path: &std::path::Path) -> Res
|
|||
let texture = renderer.render_texture(&node, Some(>k::graphene::Rect::new(0.0, 0.0, w as f32, h as f32)));
|
||||
texture.save_to_png(path).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Give a window its own Wayland app id (GTK gives every window the application's when it maps, so this follows
|
||||
/// right after). Nothing on other backends.
|
||||
pub fn set_app_id(window: >k::ApplicationWindow, app_id: &str) {
|
||||
unsafe extern "C" {
|
||||
fn gdk_wayland_toplevel_set_application_id(toplevel: *mut gtk::gdk::ffi::GdkToplevel, application_id: *const std::ffi::c_char);
|
||||
}
|
||||
let app_id = std::ffi::CString::new(app_id).expect("no NUL");
|
||||
window.connect_map(move |w| {
|
||||
let Some(surface) = w.surface() else { return };
|
||||
if surface.type_().name() != "GdkWaylandToplevel" {
|
||||
return;
|
||||
}
|
||||
let Ok(toplevel) = surface.downcast::<gtk::gdk::Toplevel>() else { return };
|
||||
unsafe { gdk_wayland_toplevel_set_application_id(gtk::glib::translate::ToGlibPtr::to_glib_none(&toplevel).0, app_id.as_ptr()) };
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue