Skip to content

Commit

Permalink
monitors: various bug fixes and tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
DashieTM committed Jun 4, 2024
1 parent 882179b commit 6d8e2c7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
12 changes: 8 additions & 4 deletions monitors/src/backend/hyprland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ pub fn hy_save_monitor_configuration(monitors: &Vec<Monitor>) {
let mut monitor_string = String::new();

for monitor in monitors {
let vrr = if monitor.vrr { 1 } else { 0 };
if !monitor.enabled {
monitor_string += &format!("keyword monitor {},disabled;", monitor.name);
} else {
monitor_string += &format!(
"monitor={},{}x{}@{},{}x{},{:.6},transform,{}\n",
"monitor={},{}x{}@{},{}x{},{:.6},transform,{},vrr,{}\n",
monitor.name,
monitor.size.0,
monitor.size.1,
Expand All @@ -112,6 +113,7 @@ pub fn hy_save_monitor_configuration(monitors: &Vec<Monitor>) {
monitor.offset.1,
monitor.scale,
monitor.transform,
vrr
);
}
}
Expand Down Expand Up @@ -165,7 +167,7 @@ impl HyprMonitor {
self.scale,
self.transform as u32,
self.vrr,
self.vrr,
false,
self.x as i32,
self.y as i32,
self.width as i32,
Expand All @@ -180,19 +182,21 @@ fn monitor_to_configstring(monitors: &Vec<Monitor>) -> String {
let mut strings = Vec::new();

for monitor in monitors {
let vrr = if monitor.vrr { 1 } else { 0 };
if !monitor.enabled {
strings.push(format!("keyword monitor {},disabled;", monitor.name));
} else {
strings.push(format!(
"keyword monitor {},{}x{}@{},{}x{},{:.6},transform,{};",
"keyword monitor {},{}x{}@{},{}x{},{:.6},transform,{},vrr,{};",
monitor.name,
&monitor.size.0,
&monitor.size.1,
&monitor.refresh_rate,
&monitor.offset.0,
&monitor.offset.1,
&monitor.scale,
&monitor.transform
&monitor.transform,
vrr
));
}
}
Expand Down
11 changes: 10 additions & 1 deletion monitors/src/frontend/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ pub fn arbitrary_add_scaling_adjustment(
monitors: Rc<RefCell<Vec<Monitor>>>,
settings: &PreferencesGroup,
) {
let scaling_adjustment = gtk::Adjustment::new(scale, 0.1, 10.0, 0.05, 0.0, 0.0);
let scaling_adjustment = gtk::Adjustment::new(scale, 0.1, 4.0, 0.05, 0.0, 0.0);
let scaling = adw::SpinRow::new(Some(&scaling_adjustment), 0.000001, 2);
scaling.set_tooltip_markup(Some("This allows you to set your own custom scale.\nPlease note, that the scale needs to result in a full number for both width and height of the resolution."));
scaling.set_title("Scaling");
scaling.connect_value_notify(move |state| {
scaling_update(state, monitors.clone(), monitor_index);
Expand All @@ -42,6 +43,7 @@ pub fn add_save_button(
.halign(gtk::Align::End)
.sensitive(false)
.build();
button.set_tooltip_markup(Some("Persistant saving of configuration"));
button.connect_clicked(move |_| {
apply_monitor_clicked(
save_ref.clone(),
Expand Down Expand Up @@ -78,6 +80,7 @@ pub fn add_primary_monitor_option(
let primary = adw::SwitchRow::new();
primary.set_title("Primary Monitor");
primary.set_active(primary_value);
primary.set_tooltip_markup(Some("Changes your primary monitor"));

if monitors.borrow().len() < 2 {
return;
Expand Down Expand Up @@ -119,6 +122,11 @@ pub fn add_vrr_monitor_option(
let vrr = adw::SwitchRow::new();
vrr.set_title("Variable Refresh-Rate");
vrr.set_active(vrr_value);
if get_environment().as_str() == "Hyprland" {
vrr.set_tooltip_markup(Some("Please note that this option will set the configuration for this monitor, however, if your monitor does not offer VRR, this setting will fail to make a change."));
} else {
vrr.set_tooltip_markup(Some("Enable or disable Variable Refresh Rate"));
}
vrr.connect_active_notify(move |state| {
monitors.borrow_mut().get_mut(monitor_index).unwrap().vrr = state.is_active();
state
Expand Down Expand Up @@ -152,6 +160,7 @@ pub fn add_enabled_monitor_option(
.subtitle(&monitor.make)
.active(monitor.enabled)
.build();
enabled.set_tooltip_markup(Some("Disables or enables monitors"));
let enabled_ref = monitors_ref.clone();
enabled.connect_active_notify(move |state| {
enabled_ref
Expand Down
11 changes: 8 additions & 3 deletions monitors/src/frontend/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub fn apply_monitor_clicked(
};
}
monitor_ref.replace(get_monitor_data());
fallback.replace(monitor_ref.borrow().clone());
settings_ref.append(&get_monitor_settings_group(
monitor_ref.clone(),
index,
Expand Down Expand Up @@ -234,6 +235,7 @@ pub fn get_monitor_settings_group(
"270-flipped",
]);
let transform = adw::ComboRow::new();
transform.set_tooltip_markup(Some("Changes the orientation of the monitor"));
transform.set_title("Transform");
transform.set_model(Some(&model_list));
match monitor.transform {
Expand Down Expand Up @@ -290,6 +292,7 @@ pub fn get_monitor_settings_group(
model_list.append(&(x.to_string() + "x" + &y.to_string()));
}
let resolution = adw::ComboRow::new();
resolution.set_tooltip_markup(Some("Changes the current resolution"));
resolution.set_title("Resolution");
resolution.set_model(Some(&model_list));
resolution.set_selected(index as u32);
Expand Down Expand Up @@ -351,6 +354,7 @@ pub fn get_monitor_settings_group(
let refresh_rate_model = StringList::new(&refresh_rates);
refresh_rate.set_model(Some(&refresh_rate_model));
refresh_rate.set_title("Refresh-Rate");
refresh_rate.set_tooltip_markup(Some("Changes the current refresh-rate"));
refresh_rate.set_selected(index as u32);
let refresh_rate_ref = clicked_monitor.clone();
refresh_rate.connect_selected_item_notify(move |dropdown| {
Expand Down Expand Up @@ -650,12 +654,13 @@ pub fn drawing_callback(
if monitor.drag_information.drag_active || monitor.drag_information.clicked {
context.set_source_color(&selected_text_color);
}
context.set_font_size((140 / factor) as f64);
context.move_to((offset_x + 10) as f64, (offset_y + 30) as f64);
// context.set_font_size((140 / factor) as f64);
context.set_font_size(20.0);
context.move_to((offset_x + 10) as f64, (offset_y + 25) as f64);
context
.show_text(&monitor.name.clone())
.expect("Could not draw text");
context.move_to((offset_x + 10) as f64, (offset_y + 60) as f64);
context.move_to((offset_x + 10) as f64, (offset_y + 45) as f64);
context
.show_text(&(monitor.size.0.to_string() + ":" + &monitor.size.1.to_string()))
.expect("Could not draw text");
Expand Down
6 changes: 5 additions & 1 deletion monitors/src/frontend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@ pub extern "C" fn frontend_data() -> (SidebarInfo, Vec<gtk::Box>) {
.sensitive(false)
.build();
config_buttons.append(&apply);
apply.set_tooltip_markup(Some("Temporarily saves configuration"));

let reset = gtk::Button::builder()
.label("Reset")
.hexpand_set(false)
.halign(gtk::Align::End)
.sensitive(false)
.build();
reset.set_tooltip_markup(Some(
"Resets currently set configuration to the last saved/applied one",
));
config_buttons.append(&reset);

let settings_box = gtk::Box::new(Orientation::Vertical, 5);
Expand Down Expand Up @@ -213,7 +217,7 @@ pub extern "C" fn frontend_data() -> (SidebarInfo, Vec<gtk::Box>) {

let env = get_environment();
let env = env.as_str();
let disallow_gaps = is_gnome() || env == "KDE" ;
let disallow_gaps = is_gnome() || env == "KDE";
let gesture = GestureDrag::builder().build();
let drawing_ref_drag_start = drawing_area.clone();
gesture.connect_drag_begin(move |_drag, x, y| {
Expand Down

0 comments on commit 6d8e2c7

Please sign in to comment.