Skip to content

Commit fc7d87f

Browse files
committed
Migrate to io.elementary.Platform 6. Optimize resize
1 parent 1254824 commit fc7d87f

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

com.github.subhadeepjasu.pebbles.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
app-id: com.github.subhadeepjasu.pebbles
22
runtime: io.elementary.Platform
3-
runtime-version: 'daily'
3+
runtime-version: '6'
44
sdk: io.elementary.Sdk
55
command: com.github.subhadeepjasu.pebbles
66
finish-args:

src/Application.vala

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,25 @@ namespace Pebbles {
5050
);
5151
X.init_threads ();
5252
settings = Settings.get_default ();
53+
54+
Timeout.add_seconds (1, () => {
55+
if (this.get_active_window () != null) {
56+
int height = this.get_active_window ().get_allocated_height ();
57+
if (((MainWindow) (this.get_active_window ())).previous_height != height) {
58+
((MainWindow) (this.get_active_window ())).previous_height = height;
59+
adjust_font_responsive (height);
60+
}
61+
return true;
62+
}
63+
return false;
64+
});
5365
}
5466

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

5971
mainwindow.present ();
60-
mainwindow.configure_event.connect ((event) => {
61-
adjust_font_responsive (event);
62-
return false;
63-
});
6472
}
6573

6674
public override int command_line (ApplicationCommandLine cmd) {
@@ -122,11 +130,11 @@ namespace Pebbles {
122130
private double map_range (double input, double input_start, double input_end, double output_start, double output_end) {
123131
return output_start + ((output_end - output_start) / (input_end - input_start)) * (input - input_start);
124132
}
125-
private void adjust_font_responsive (Gdk.EventConfigure event) {
133+
private void adjust_font_responsive (int height) {
126134
try {
127-
var target_size_h1 = (int)map_range (double.max((double) event.height/600, 1), 1, 2, 40, 120);
128-
var target_size_h2 = (int)map_range (double.max((double) event.height/600, 1), 1, 2, 20, 50);
129-
var target_size_h4 = (int)map_range (double.max((double) event.height/600, 1), 1, 2, 10, 20);
135+
var target_size_h1 = (int)map_range (double.max((double) height/600, 1), 1, 2, 40, 120);
136+
var target_size_h2 = (int)map_range (double.max((double) height/600, 1), 1, 2, 20, 50);
137+
var target_size_h4 = (int)map_range (double.max((double) height/600, 1), 1, 2, 10, 20);
130138
var css = DISPLAY_FONT_SIZE_TEMPLATE.printf(target_size_h1, target_size_h2, target_size_h4);
131139
font_size_provider.load_from_data (css, -1);
132140
} catch (Error e) {

src/MainWindow.vala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ namespace Pebbles {
124124
/// Initialized
125125
bool initialized = false;
126126

127+
public int previous_height = 0;
128+
127129
public MainWindow () {
128130
settings = Pebbles.Settings.get_default ();
129131
this.delete_event.connect (() => {

0 commit comments

Comments
 (0)