shell: Make active hint size configurable

This commit is contained in:
Victoria Brekenfeld 2023-03-09 18:27:11 +01:00
parent 6492cfb96a
commit 4bf2c8df79
7 changed files with 58 additions and 26 deletions

View file

@ -66,8 +66,6 @@ pub type GlMultiFrame<'a, 'b, 'frame> =
pub static CLEAR_COLOR: [f32; 4] = [0.153, 0.161, 0.165, 1.0];
pub static FOCUS_INDICATOR_COLOR: [f32; 4] = [0.580, 0.921, 0.921, 1.0];
pub static FOCUS_INDICATOR_THICKNESS: f32 = 4.0;
pub static FOCUS_INDICATOR_RADIUS: f32 = 8.0;
pub static FOCUS_INDICATOR_SHADER: &str = include_str!("./shaders/focus_indicator.frag");
pub struct IndicatorShader(pub Gles2PixelProgram);
@ -87,8 +85,9 @@ impl IndicatorShader {
pub fn element<R: AsGlowRenderer>(
renderer: &R,
geo: Rectangle<i32, Logical>,
thickness: u8,
) -> PixelShaderElement {
let thickness = FOCUS_INDICATOR_THICKNESS;
let thickness: f32 = thickness as f32;
let thickness_loc = (thickness as i32, thickness as i32);
let thickness_size = ((thickness * 2.0) as i32, (thickness * 2.0) as i32);
let geo = Rectangle::from_loc_and_size(
@ -120,7 +119,7 @@ impl IndicatorShader {
vec![
Uniform::new("color", [color[0], color[1], color[2]]),
Uniform::new("thickness", thickness),
Uniform::new("radius", FOCUS_INDICATOR_RADIUS),
Uniform::new("radius", thickness * 2.0),
],
);
if !user_data.insert_if_missing(|| IndicatorElement(RefCell::new(elem.clone()))) {
@ -301,6 +300,7 @@ where
&state.shell.override_redirect_windows,
state.xwayland_state.as_mut(),
(!move_active && active_output).then_some(&last_active_seat),
state.config.static_conf.active_hint,
exclude_workspace_overview,
)
.map_err(|_| OutputNoMode)?

View file

@ -37,6 +37,8 @@ pub struct StaticConfig {
pub workspace_mode: WorkspaceMode,
pub workspace_amount: WorkspaceAmount,
pub tiling_enabled: bool,
#[serde(default = "default_active_hint")]
pub active_hint: u8,
}
#[derive(Debug, Deserialize, Clone, Copy, PartialEq, Eq)]
@ -77,6 +79,10 @@ fn default_enabled() -> bool {
true
}
fn default_active_hint() -> u8 {
4
}
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
pub struct OutputConfig {
pub mode: ((i32, i32), Option<u32>),
@ -221,6 +227,7 @@ impl Config {
workspace_mode: WorkspaceMode::Global,
workspace_amount: WorkspaceAmount::Dynamic,
tiling_enabled: false,
active_hint: default_active_hint(),
}
}

View file

@ -34,6 +34,7 @@ pub type SeatMoveGrabState = RefCell<Option<MoveGrabState>>;
pub struct MoveGrabState {
window: CosmicMapped,
window_offset: Point<i32, Logical>,
indicator_thickness: u8,
}
impl MoveGrabState {
@ -59,11 +60,17 @@ impl MoveGrabState {
let scale = output.current_scale().fractional_scale().into();
let render_location = cursor_at.to_i32_round() - output.geometry().loc + self.window_offset;
let mut elements: Vec<I> = vec![CosmicMappedRenderElement::from(IndicatorShader::element(
renderer,
Rectangle::from_loc_and_size(render_location, self.window.geometry().size),
))
.into()];
let mut elements: Vec<I> = Vec::new();
if self.indicator_thickness > 0 {
elements.push(
CosmicMappedRenderElement::from(IndicatorShader::element(
renderer,
Rectangle::from_loc_and_size(render_location, self.window.geometry().size),
self.indicator_thickness,
))
.into(),
);
}
elements.extend(AsRenderElements::<R>::render_elements::<I>(
&self.window,
renderer,
@ -172,6 +179,7 @@ impl MoveSurfaceGrab {
seat: &Seat<State>,
initial_cursor_location: Point<f64, Logical>,
initial_window_location: Point<i32, Logical>,
indicator_thickness: u8,
) -> MoveSurfaceGrab {
let output = seat.active_output();
let mut outputs = HashSet::new();
@ -182,6 +190,7 @@ impl MoveSurfaceGrab {
window: window.clone(),
window_offset: dbg!(initial_window_location)
- dbg!(initial_cursor_location.to_i32_round()),
indicator_thickness,
};
*seat

View file

@ -349,6 +349,7 @@ impl FloatingLayout {
renderer: &mut R,
output: &Output,
focused: Option<&CosmicMapped>,
indicator_thickness: u8,
) -> Vec<CosmicMappedRenderElement<R>>
where
R: Renderer + ImportAll + ImportMem + AsGlowRenderer,
@ -372,14 +373,17 @@ impl FloatingLayout {
output_scale.into(),
);
if focused == Some(elem) {
let element = IndicatorShader::element(
renderer,
Rectangle::from_loc_and_size(
self.space.element_location(elem).unwrap(),
elem.geometry().size,
),
);
elements.insert(0, element.into());
if indicator_thickness > 0 {
let element = IndicatorShader::element(
renderer,
Rectangle::from_loc_and_size(
self.space.element_location(elem).unwrap(),
elem.geometry().size,
),
indicator_thickness,
);
elements.insert(0, element.into());
}
}
elements
})

View file

@ -1306,6 +1306,7 @@ impl TilingLayout {
renderer: &mut R,
output: &Output,
focused: Option<&CosmicMapped>,
indicator_thickness: u8,
) -> Result<Vec<CosmicMappedRenderElement<R>>, OutputNotMapped>
where
R: Renderer + ImportAll + ImportMem + AsGlowRenderer,
@ -1383,11 +1384,14 @@ impl TilingLayout {
Scale::from(output_scale),
);
if focused == Some(mapped) {
let element = IndicatorShader::element(
renderer,
Rectangle::from_loc_and_size(loc, mapped.geometry().size),
);
elements.insert(0, element.into());
if indicator_thickness > 0 {
let element = IndicatorShader::element(
renderer,
Rectangle::from_loc_and_size(loc, mapped.geometry().size),
indicator_thickness,
);
elements.insert(0, element.into());
}
}
elements
})

View file

@ -1278,8 +1278,13 @@ impl Shell {
.windows()
.find(|(w, _)| w.wl_surface().as_ref() == Some(surface))
.unwrap();
if let Some(grab) = workspace.move_request(&window, &seat, &output, start_data)
{
if let Some(grab) = workspace.move_request(
&window,
&seat,
&output,
start_data,
state.common.config.static_conf.active_hint,
) {
let handle = workspace.handle;
state
.common

View file

@ -319,6 +319,7 @@ impl Workspace {
seat: &Seat<State>,
output: &Output,
start_data: PointerGrabStartData<State>,
indicator_thickness: u8,
) -> Option<MoveSurfaceGrab> {
let pointer = seat.get_pointer().unwrap();
let pos = pointer.current_location();
@ -348,6 +349,7 @@ impl Workspace {
seat,
pos,
initial_window_location,
indicator_thickness,
))
} else {
None // TODO
@ -439,6 +441,7 @@ impl Workspace {
override_redirect_windows: &[X11Surface],
xwm_state: Option<&'a mut XWaylandState>,
draw_focus_indicator: Option<&Seat<State>>,
indicator_thickness: u8,
exclude_workspace_overview: bool,
) -> Result<Vec<WorkspaceRenderElement<R>>, OutputNotMapped>
where
@ -572,7 +575,7 @@ impl Workspace {
// floating surfaces
render_elements.extend(
self.floating_layer
.render_output::<R>(renderer, output, focused.as_ref())
.render_output::<R>(renderer, output, focused.as_ref(), indicator_thickness)
.into_iter()
.map(WorkspaceRenderElement::from),
);
@ -580,7 +583,7 @@ impl Workspace {
//tiling surfaces
render_elements.extend(
self.tiling_layer
.render_output::<R>(renderer, output, focused.as_ref())?
.render_output::<R>(renderer, output, focused.as_ref(), indicator_thickness)?
.into_iter()
.map(WorkspaceRenderElement::from),
);