diff --git a/src/config/handler.rs b/src/config/handler.rs index e5095410..6fcf6ce5 100644 --- a/src/config/handler.rs +++ b/src/config/handler.rs @@ -90,6 +90,7 @@ use { mod dispatch; mod matchers; mod outputs; +mod theme; mod windows; pub(super) struct ConfigProxyHandler { @@ -1112,76 +1113,6 @@ impl ConfigProxyHandler { Ok(()) } - fn handle_set_float_above_fullscreen(&self, above: bool) { - self.state.set_float_above_fullscreen(above); - } - - fn handle_get_float_above_fullscreen(&self) { - self.respond(Response::GetFloatAboveFullscreen { - above: self.state.float_above_fullscreen.get(), - }); - } - - fn handle_set_show_bar(&self, show: bool) { - self.state.set_show_bar(show); - } - - fn handle_get_show_bar(&self) { - self.respond(Response::GetShowBar { - show: self.state.show_bar.get(), - }); - } - - fn handle_set_show_titles(&self, _show: bool) { - // no-op: titles have been removed - } - - fn handle_get_show_titles(&self) { - self.respond(Response::GetShowTitles { show: false }); - } - - fn handle_set_floating_titles(&self, _floating: bool) { - // no-op: titles have been removed - } - - fn handle_get_floating_titles(&self) { - self.respond(Response::GetFloatingTitles { floating: false }); - } - - fn handle_set_bar_position(&self, position: BarPosition) -> Result<(), CphError> { - let Ok(position) = position.try_into() else { - return Err(CphError::UnknownBarPosition(position)); - }; - self.state.set_bar_position(position); - Ok(()) - } - - fn handle_get_bar_position(&self) { - self.respond(Response::GetBarPosition { - position: self.state.theme.bar_position.get().into(), - }); - } - - fn handle_set_corner_radius(&self, radius: f32) { - use crate::theme::CornerRadius; - let radius = radius.max(0.0).min(1000.0); - self.state - .theme - .corner_radius - .set(CornerRadius::from(radius)); - self.state.damage(self.state.root.extents.get()); - } - - fn handle_get_corner_radius(&self) { - self.respond(Response::GetCornerRadius { - radius: self.state.theme.corner_radius.get().top_left, - }); - } - - fn handle_set_show_float_pin_icon(&self, _show: bool) { - // no-op: titles have been removed, pin icon was in title bar - } - fn handle_set_workspace_display_order(&self, order: WorkspaceDisplayOrder) { self.state.set_workspace_display_order(order.into()); } @@ -1715,130 +1646,6 @@ impl ConfigProxyHandler { Ok(()) } - fn get_sized(&self, sized: Resizable) -> Result { - use jay_config::theme::sized::*; - let sized = match sized { - TITLE_HEIGHT => ThemeSized::title_height, - BORDER_WIDTH => ThemeSized::border_width, - BAR_HEIGHT => ThemeSized::bar_height, - BAR_SEPARATOR_WIDTH => ThemeSized::bar_separator_width, - GAP => ThemeSized::gap, - TITLE_GAP => ThemeSized::title_gap, - TAB_BAR_HEIGHT => ThemeSized::tab_bar_height, - TAB_BAR_PADDING => ThemeSized::tab_bar_padding, - TAB_BAR_RADIUS => ThemeSized::tab_bar_radius, - TAB_BAR_BORDER_WIDTH => ThemeSized::tab_bar_border_width, - TAB_BAR_TEXT_PADDING => ThemeSized::tab_bar_text_padding, - TAB_BAR_GAP => ThemeSized::tab_bar_gap, - _ => return Err(CphError::UnknownSized(sized.0)), - }; - Ok(sized) - } - - fn handle_get_size(&self, sized: Resizable) -> Result<(), CphError> { - let sized = self.get_sized(sized)?; - let size = sized.field(&self.state.theme).val.get(); - self.respond(Response::GetSize { size }); - Ok(()) - } - - fn handle_set_size(&self, sized: Resizable, size: i32) -> Result<(), CphError> { - let sized = self.get_sized(sized)?; - if size < sized.min() { - return Err(CphError::InvalidSize(size, sized)); - } - if size > sized.max() { - return Err(CphError::InvalidSize(size, sized)); - } - self.state.set_size(sized, size); - Ok(()) - } - - fn handle_reset_colors(&self) { - self.state.reset_colors(); - } - - fn handle_reset_sizes(&self) { - self.state.reset_sizes(); - } - - fn handle_reset_font(&self) { - self.state.reset_fonts(); - } - - fn handle_set_font(&self, font: &str) { - self.state.set_font(font); - } - - fn handle_set_bar_font(&self, font: &str) { - self.state.set_bar_font(Some(font)); - } - - fn handle_set_title_font(&self, _font: &str) { - // no-op: titles have been removed - } - - fn handle_get_font(&self) { - let font = self.state.theme.font.get().to_string(); - self.respond(Response::GetFont { font }); - } - - fn get_color(&self, colorable: Colorable) -> Result { - use jay_config::theme::colors::*; - let colorable = match colorable { - UNFOCUSED_TITLE_BACKGROUND_COLOR => ThemeColor::unfocused_title_background, - FOCUSED_TITLE_BACKGROUND_COLOR => ThemeColor::focused_title_background, - CAPTURED_UNFOCUSED_TITLE_BACKGROUND_COLOR => { - ThemeColor::captured_unfocused_title_background - } - CAPTURED_FOCUSED_TITLE_BACKGROUND_COLOR => { - ThemeColor::captured_focused_title_background - } - FOCUSED_INACTIVE_TITLE_BACKGROUND_COLOR => { - ThemeColor::focused_inactive_title_background - } - BACKGROUND_COLOR => ThemeColor::background, - BAR_BACKGROUND_COLOR => ThemeColor::bar_background, - SEPARATOR_COLOR => ThemeColor::separator, - BORDER_COLOR => ThemeColor::border, - ACTIVE_BORDER_COLOR => ThemeColor::active_border, - UNFOCUSED_TITLE_TEXT_COLOR => ThemeColor::unfocused_title_text, - FOCUSED_TITLE_TEXT_COLOR => ThemeColor::focused_title_text, - FOCUSED_INACTIVE_TITLE_TEXT_COLOR => ThemeColor::focused_inactive_title_text, - BAR_STATUS_TEXT_COLOR => ThemeColor::bar_text, - ATTENTION_REQUESTED_BACKGROUND_COLOR => ThemeColor::attention_requested_background, - HIGHLIGHT_COLOR => ThemeColor::highlight, - TAB_ACTIVE_BACKGROUND_COLOR => ThemeColor::tab_active_background, - TAB_ACTIVE_BORDER_COLOR => ThemeColor::tab_active_border, - TAB_INACTIVE_BACKGROUND_COLOR => ThemeColor::tab_inactive_background, - TAB_INACTIVE_BORDER_COLOR => ThemeColor::tab_inactive_border, - TAB_ACTIVE_TEXT_COLOR => ThemeColor::tab_active_text, - TAB_INACTIVE_TEXT_COLOR => ThemeColor::tab_inactive_text, - TAB_BAR_BACKGROUND_COLOR => ThemeColor::tab_bar_background, - TAB_ATTENTION_BACKGROUND_COLOR => ThemeColor::tab_attention_background, - _ => return Err(CphError::UnknownColor(colorable.0)), - }; - Ok(colorable) - } - - fn handle_get_color(&self, colorable: Colorable) -> Result<(), CphError> { - let color = self.get_color(colorable)?.field(&self.state.theme).get(); - let [r, g, b, a] = color.to_array(Eotf::Gamma22); - let color = jay_config::theme::Color::new_f32_premultiplied(r, g, b, a); - self.respond(Response::GetColor { color }); - Ok(()) - } - - fn handle_set_color( - &self, - colorable: Colorable, - color: jay_config::theme::Color, - ) -> Result<(), CphError> { - self.state - .set_color(self.get_color(colorable)?, color.into()); - Ok(()) - } - fn handle_destroy_keymap(&self, keymap: Keymap) { self.keymaps.remove(&keymap); } diff --git a/src/config/handler/theme.rs b/src/config/handler/theme.rs new file mode 100644 index 00000000..ba56307d --- /dev/null +++ b/src/config/handler/theme.rs @@ -0,0 +1,200 @@ +use super::*; + +impl ConfigProxyHandler { + pub(super) fn handle_set_float_above_fullscreen(&self, above: bool) { + self.state.set_float_above_fullscreen(above); + } + + pub(super) fn handle_get_float_above_fullscreen(&self) { + self.respond(Response::GetFloatAboveFullscreen { + above: self.state.float_above_fullscreen.get(), + }); + } + + pub(super) fn handle_set_show_bar(&self, show: bool) { + self.state.set_show_bar(show); + } + + pub(super) fn handle_get_show_bar(&self) { + self.respond(Response::GetShowBar { + show: self.state.show_bar.get(), + }); + } + + pub(super) fn handle_set_show_titles(&self, _show: bool) { + // no-op: titles have been removed + } + + pub(super) fn handle_get_show_titles(&self) { + self.respond(Response::GetShowTitles { show: false }); + } + + pub(super) fn handle_set_floating_titles(&self, _floating: bool) { + // no-op: titles have been removed + } + + pub(super) fn handle_get_floating_titles(&self) { + self.respond(Response::GetFloatingTitles { floating: false }); + } + + pub(super) fn handle_set_bar_position( + &self, + position: BarPosition, + ) -> Result<(), CphError> { + let Ok(position) = position.try_into() else { + return Err(CphError::UnknownBarPosition(position)); + }; + self.state.set_bar_position(position); + Ok(()) + } + + pub(super) fn handle_get_bar_position(&self) { + self.respond(Response::GetBarPosition { + position: self.state.theme.bar_position.get().into(), + }); + } + + pub(super) fn handle_set_corner_radius(&self, radius: f32) { + use crate::theme::CornerRadius; + let radius = radius.max(0.0).min(1000.0); + self.state + .theme + .corner_radius + .set(CornerRadius::from(radius)); + self.state.damage(self.state.root.extents.get()); + } + + pub(super) fn handle_get_corner_radius(&self) { + self.respond(Response::GetCornerRadius { + radius: self.state.theme.corner_radius.get().top_left, + }); + } + + pub(super) fn handle_set_show_float_pin_icon(&self, _show: bool) { + // no-op: titles have been removed, pin icon was in title bar + } + + fn get_sized(&self, sized: Resizable) -> Result { + use jay_config::theme::sized::*; + let sized = match sized { + TITLE_HEIGHT => ThemeSized::title_height, + BORDER_WIDTH => ThemeSized::border_width, + BAR_HEIGHT => ThemeSized::bar_height, + BAR_SEPARATOR_WIDTH => ThemeSized::bar_separator_width, + GAP => ThemeSized::gap, + TITLE_GAP => ThemeSized::title_gap, + TAB_BAR_HEIGHT => ThemeSized::tab_bar_height, + TAB_BAR_PADDING => ThemeSized::tab_bar_padding, + TAB_BAR_RADIUS => ThemeSized::tab_bar_radius, + TAB_BAR_BORDER_WIDTH => ThemeSized::tab_bar_border_width, + TAB_BAR_TEXT_PADDING => ThemeSized::tab_bar_text_padding, + TAB_BAR_GAP => ThemeSized::tab_bar_gap, + _ => return Err(CphError::UnknownSized(sized.0)), + }; + Ok(sized) + } + + pub(super) fn handle_get_size(&self, sized: Resizable) -> Result<(), CphError> { + let sized = self.get_sized(sized)?; + let size = sized.field(&self.state.theme).val.get(); + self.respond(Response::GetSize { size }); + Ok(()) + } + + pub(super) fn handle_set_size(&self, sized: Resizable, size: i32) -> Result<(), CphError> { + let sized = self.get_sized(sized)?; + if size < sized.min() { + return Err(CphError::InvalidSize(size, sized)); + } + if size > sized.max() { + return Err(CphError::InvalidSize(size, sized)); + } + self.state.set_size(sized, size); + Ok(()) + } + + pub(super) fn handle_reset_colors(&self) { + self.state.reset_colors(); + } + + pub(super) fn handle_reset_sizes(&self) { + self.state.reset_sizes(); + } + + pub(super) fn handle_reset_font(&self) { + self.state.reset_fonts(); + } + + pub(super) fn handle_set_font(&self, font: &str) { + self.state.set_font(font); + } + + pub(super) fn handle_set_bar_font(&self, font: &str) { + self.state.set_bar_font(Some(font)); + } + + pub(super) fn handle_set_title_font(&self, _font: &str) { + // no-op: titles have been removed + } + + pub(super) fn handle_get_font(&self) { + let font = self.state.theme.font.get().to_string(); + self.respond(Response::GetFont { font }); + } + + fn get_color(&self, colorable: Colorable) -> Result { + use jay_config::theme::colors::*; + let colorable = match colorable { + UNFOCUSED_TITLE_BACKGROUND_COLOR => ThemeColor::unfocused_title_background, + FOCUSED_TITLE_BACKGROUND_COLOR => ThemeColor::focused_title_background, + CAPTURED_UNFOCUSED_TITLE_BACKGROUND_COLOR => { + ThemeColor::captured_unfocused_title_background + } + CAPTURED_FOCUSED_TITLE_BACKGROUND_COLOR => { + ThemeColor::captured_focused_title_background + } + FOCUSED_INACTIVE_TITLE_BACKGROUND_COLOR => { + ThemeColor::focused_inactive_title_background + } + BACKGROUND_COLOR => ThemeColor::background, + BAR_BACKGROUND_COLOR => ThemeColor::bar_background, + SEPARATOR_COLOR => ThemeColor::separator, + BORDER_COLOR => ThemeColor::border, + ACTIVE_BORDER_COLOR => ThemeColor::active_border, + UNFOCUSED_TITLE_TEXT_COLOR => ThemeColor::unfocused_title_text, + FOCUSED_TITLE_TEXT_COLOR => ThemeColor::focused_title_text, + FOCUSED_INACTIVE_TITLE_TEXT_COLOR => ThemeColor::focused_inactive_title_text, + BAR_STATUS_TEXT_COLOR => ThemeColor::bar_text, + ATTENTION_REQUESTED_BACKGROUND_COLOR => ThemeColor::attention_requested_background, + HIGHLIGHT_COLOR => ThemeColor::highlight, + TAB_ACTIVE_BACKGROUND_COLOR => ThemeColor::tab_active_background, + TAB_ACTIVE_BORDER_COLOR => ThemeColor::tab_active_border, + TAB_INACTIVE_BACKGROUND_COLOR => ThemeColor::tab_inactive_background, + TAB_INACTIVE_BORDER_COLOR => ThemeColor::tab_inactive_border, + TAB_ACTIVE_TEXT_COLOR => ThemeColor::tab_active_text, + TAB_INACTIVE_TEXT_COLOR => ThemeColor::tab_inactive_text, + TAB_BAR_BACKGROUND_COLOR => ThemeColor::tab_bar_background, + TAB_ATTENTION_BACKGROUND_COLOR => ThemeColor::tab_attention_background, + _ => return Err(CphError::UnknownColor(colorable.0)), + }; + Ok(colorable) + } + + pub(super) fn handle_get_color(&self, colorable: Colorable) -> Result<(), CphError> { + let color = self.get_color(colorable)?.field(&self.state.theme).get(); + let [r, g, b, a] = color.to_array(Eotf::Gamma22); + let color = jay_config::theme::Color::new_f32_premultiplied(r, g, b, a); + self.respond(Response::GetColor { color }); + Ok(()) + } + + pub(super) fn handle_set_color( + &self, + colorable: Colorable, + color: jay_config::theme::Color, + ) -> Result<(), CphError> { + self.state + .set_color(self.get_color(colorable)?, color.into()); + Ok(()) + } +}