Skip to content

Commit

Permalink
Migrate to io.elementary.Platform 6. Optimize resize
Browse files Browse the repository at this point in the history
  • Loading branch information
SubhadeepJasu committed Jul 25, 2021
1 parent 1254824 commit fc7d87f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion com.github.subhadeepjasu.pebbles.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
app-id: com.github.subhadeepjasu.pebbles
runtime: io.elementary.Platform
runtime-version: 'daily'
runtime-version: '6'
sdk: io.elementary.Sdk
command: com.github.subhadeepjasu.pebbles
finish-args:
Expand Down
24 changes: 16 additions & 8 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,25 @@ namespace Pebbles {
);
X.init_threads ();
settings = Settings.get_default ();

Timeout.add_seconds (1, () => {
if (this.get_active_window () != null) {
int height = this.get_active_window ().get_allocated_height ();
if (((MainWindow) (this.get_active_window ())).previous_height != height) {
((MainWindow) (this.get_active_window ())).previous_height = height;
adjust_font_responsive (height);
}
return true;
}
return false;
});
}

protected override void activate () {
var mainwindow = new MainWindow ();
mainwindow.application = this;

mainwindow.present ();
mainwindow.configure_event.connect ((event) => {
adjust_font_responsive (event);
return false;
});
}

public override int command_line (ApplicationCommandLine cmd) {
Expand Down Expand Up @@ -122,11 +130,11 @@ namespace Pebbles {
private double map_range (double input, double input_start, double input_end, double output_start, double output_end) {
return output_start + ((output_end - output_start) / (input_end - input_start)) * (input - input_start);
}
private void adjust_font_responsive (Gdk.EventConfigure event) {
private void adjust_font_responsive (int height) {
try {
var target_size_h1 = (int)map_range (double.max((double) event.height/600, 1), 1, 2, 40, 120);
var target_size_h2 = (int)map_range (double.max((double) event.height/600, 1), 1, 2, 20, 50);
var target_size_h4 = (int)map_range (double.max((double) event.height/600, 1), 1, 2, 10, 20);
var target_size_h1 = (int)map_range (double.max((double) height/600, 1), 1, 2, 40, 120);
var target_size_h2 = (int)map_range (double.max((double) height/600, 1), 1, 2, 20, 50);
var target_size_h4 = (int)map_range (double.max((double) height/600, 1), 1, 2, 10, 20);
var css = DISPLAY_FONT_SIZE_TEMPLATE.printf(target_size_h1, target_size_h2, target_size_h4);
font_size_provider.load_from_data (css, -1);
} catch (Error e) {
Expand Down
2 changes: 2 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ namespace Pebbles {
/// Initialized
bool initialized = false;

public int previous_height = 0;

public MainWindow () {
settings = Pebbles.Settings.get_default ();
this.delete_event.connect (() => {
Expand Down

0 comments on commit fc7d87f

Please sign in to comment.