Skip to content

Commit 20b5e4a

Browse files
committed
feat: Allow configuring horizontal/vertical window size
This can be useful for large or ultrawide monitors. For now, the window position is always centered, but that could be made configurable in a future iteration, if desired.
1 parent a09bff0 commit 20b5e4a

File tree

8 files changed

+135
-45
lines changed

8 files changed

+135
-45
lines changed

ddterm/app/application.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,10 @@ class Application extends Gtk.Application {
292292

293293
const shortcut_actions = {
294294
'shortcut-window-hide': 'win.hide',
295-
'shortcut-window-size-inc': 'win.window-size-inc',
296-
'shortcut-window-size-dec': 'win.window-size-dec',
295+
'shortcut-window-hsize-inc': 'win.window-hsize-inc',
296+
'shortcut-window-hsize-dec': 'win.window-hsize-dec',
297+
'shortcut-window-vsize-inc': 'win.window-vsize-inc',
298+
'shortcut-window-vsize-dec': 'win.window-vsize-dec',
297299
'shortcut-background-opacity-inc': 'win.background-opacity-inc',
298300
'shortcut-background-opacity-dec': 'win.background-opacity-dec',
299301
'shortcut-toggle-maximize': 'app.window-maximize',

ddterm/app/appwindow.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,25 @@ class DDTermAppWindow extends Gtk.ApplicationWindow {
269269
'toggle': this.toggle.bind(this),
270270
'show': () => this.present_with_time(Gdk.CURRENT_TIME),
271271
'hide': () => this.hide(),
272-
'window-size-dec': () => {
272+
'window-hsize-dec': () => {
273273
if (this.settings.get_boolean('window-maximize'))
274-
this.settings.set_double('window-size', 1.0 - HEIGHT_MOD);
274+
this.settings.set_double('window-hsize', 1.0 - HEIGHT_MOD);
275275
else
276-
this.adjust_double_setting('window-size', -HEIGHT_MOD);
276+
this.adjust_double_setting('window-hsize', -HEIGHT_MOD);
277277
},
278-
'window-size-inc': () => {
278+
'window-hsize-inc': () => {
279279
if (!this.settings.get_boolean('window-maximize'))
280-
this.adjust_double_setting('window-size', HEIGHT_MOD);
280+
this.adjust_double_setting('window-hsize', HEIGHT_MOD);
281+
},
282+
'window-vsize-dec': () => {
283+
if (this.settings.get_boolean('window-maximize'))
284+
this.settings.set_double('window-vsize', 1.0 - HEIGHT_MOD);
285+
else
286+
this.adjust_double_setting('window-vsize', -HEIGHT_MOD);
287+
},
288+
'window-vsize-inc': () => {
289+
if (!this.settings.get_boolean('window-maximize'))
290+
this.adjust_double_setting('window-vsize', HEIGHT_MOD);
281291
},
282292
'background-opacity-dec': () => {
283293
this.adjust_double_setting('background-opacity', -OPACITY_MOD);

ddterm/pref/positionsize.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export const PositionSizeWidget = GObject.registerClass({
3737
Children: [
3838
'monitor_combo',
3939
'window_pos_combo',
40-
'window_size_scale',
40+
'window_hsize_scale',
41+
'window_vsize_scale',
4142
],
4243
Properties: {
4344
'settings': GObject.ParamSpec.object(
@@ -104,10 +105,12 @@ export const PositionSizeWidget = GObject.registerClass({
104105
this.enable_monitor_combo();
105106

106107
bind_widget(this.settings, 'window-position', this.window_pos_combo);
107-
bind_widget(this.settings, 'window-size', this.window_size_scale);
108+
bind_widget(this.settings, 'window-hsize', this.window_hsize_scale);
109+
bind_widget(this.settings, 'window-vsize', this.window_vsize_scale);
108110

109111
const percent_format = new Intl.NumberFormat(undefined, { style: 'percent' });
110-
set_scale_value_format(this.window_size_scale, percent_format);
112+
set_scale_value_format(this.window_hsize_scale, percent_format);
113+
set_scale_value_format(this.window_vsize_scale, percent_format);
111114
}
112115

113116
get title() {

ddterm/pref/ui/prefs-position-size.ui

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ along with ddterm GNOME Shell extension. If not, see <http://www.gnu.org/licens
2424
<!-- interface-license-type gplv3 -->
2525
<!-- interface-name ddterm GNOME Shell extension -->
2626
<!-- interface-copyright 2022 Aleksandr Mezin -->
27-
<object class="GtkAdjustment" id="window_size_adjustment">
27+
<object class="GtkAdjustment" id="window_hsize_adjustment">
28+
<property name="upper">1</property>
29+
<property name="step-increment">0.01</property>
30+
<property name="page-increment">0.10</property>
31+
</object>
32+
<object class="GtkAdjustment" id="window_vsize_adjustment">
2833
<property name="upper">1</property>
2934
<property name="step-increment">0.01</property>
3035
<property name="page-increment">0.10</property>
@@ -44,21 +49,21 @@ along with ddterm GNOME Shell extension. If not, see <http://www.gnu.org/licens
4449
<property name="visible">True</property>
4550
<property name="can-focus">False</property>
4651
<property name="halign">start</property>
47-
<property name="label" translatable="yes">Window _size:</property>
52+
<property name="label" translatable="yes">Window _horizontal size:</property>
4853
<property name="use-underline">True</property>
49-
<property name="mnemonic-widget">window_size_scale</property>
54+
<property name="mnemonic-widget">window_hsize_scale</property>
5055
</object>
5156
<packing>
5257
<property name="left-attach">0</property>
5358
<property name="top-attach">5</property>
5459
</packing>
5560
</child>
5661
<child>
57-
<object class="GtkScale" id="window_size_scale">
62+
<object class="GtkScale" id="window_hsize_scale">
5863
<property name="visible">True</property>
5964
<property name="can-focus">True</property>
6065
<property name="hexpand">True</property>
61-
<property name="adjustment">window_size_adjustment</property>
66+
<property name="adjustment">window_hsize_adjustment</property>
6267
<property name="show-fill-level">True</property>
6368
<property name="round-digits">2</property>
6469
<property name="digits">2</property>
@@ -68,6 +73,35 @@ along with ddterm GNOME Shell extension. If not, see <http://www.gnu.org/licens
6873
<property name="top-attach">5</property>
6974
</packing>
7075
</child>
76+
<child>
77+
<object class="GtkLabel">
78+
<property name="visible">True</property>
79+
<property name="can-focus">False</property>
80+
<property name="halign">start</property>
81+
<property name="label" translatable="yes">Window _vertical size:</property>
82+
<property name="use-underline">True</property>
83+
<property name="mnemonic-widget">window_vsize_scale</property>
84+
</object>
85+
<packing>
86+
<property name="left-attach">0</property>
87+
<property name="top-attach">6</property>
88+
</packing>
89+
</child>
90+
<child>
91+
<object class="GtkScale" id="window_vsize_scale">
92+
<property name="visible">True</property>
93+
<property name="can-focus">True</property>
94+
<property name="hexpand">True</property>
95+
<property name="adjustment">window_vsize_adjustment</property>
96+
<property name="show-fill-level">True</property>
97+
<property name="round-digits">2</property>
98+
<property name="digits">2</property>
99+
</object>
100+
<packing>
101+
<property name="left-attach">1</property>
102+
<property name="top-attach">6</property>
103+
</packing>
104+
</child>
71105
<child>
72106
<object class="GtkLabel">
73107
<property name="visible">True</property>

ddterm/pref/ui/prefs-shortcuts.ui

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,29 @@ along with ddterm GNOME Shell extension. If not, see <http://www.gnu.org/licens
8383
<col id="4">False</col>
8484
</row>
8585
<row>
86-
<col id="0">shortcut-window-size-inc</col>
87-
<col id="1" translatable="yes">Increase Window Size</col>
86+
<col id="0">shortcut-window-hsize-inc</col>
87+
<col id="1" translatable="yes">Increase Horizontal Window Size</col>
8888
<col id="2">0</col>
8989
<col id="3">0</col>
9090
<col id="4">False</col>
9191
</row>
9292
<row>
93-
<col id="0">shortcut-window-size-dec</col>
94-
<col id="1" translatable="yes">Decrease Window Size</col>
93+
<col id="0">shortcut-window-hsize-dec</col>
94+
<col id="1" translatable="yes">Decrease Horizontal Window Size</col>
95+
<col id="2">0</col>
96+
<col id="3">0</col>
97+
<col id="4">False</col>
98+
</row>
99+
<row>
100+
<col id="0">shortcut-window-vsize-inc</col>
101+
<col id="1" translatable="yes">Increase Vertical Window Size</col>
102+
<col id="2">0</col>
103+
<col id="3">0</col>
104+
<col id="4">False</col>
105+
</row>
106+
<row>
107+
<col id="0">shortcut-window-vsize-dec</col>
108+
<col id="1" translatable="yes">Decrease Vertical Window Size</col>
95109
<col id="2">0</col>
96110
<col id="3">0</col>
97111
<col id="4">False</col>

ddterm/shell/geometry.js

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,17 @@ export const WindowGeometry = GObject.registerClass({
8282
Meta.MaximizeFlags,
8383
Meta.MaximizeFlags.VERTICAL
8484
),
85-
'window-size': GObject.ParamSpec.double(
86-
'window-size',
85+
'window-hsize': GObject.ParamSpec.double(
86+
'window-hsize',
87+
'',
88+
'',
89+
GObject.ParamFlags.READWRITE | GObject.ParamFlags.EXPLICIT_NOTIFY,
90+
0,
91+
1,
92+
1
93+
),
94+
'window-vsize': GObject.ParamSpec.double(
95+
'window-vsize',
8796
'',
8897
'',
8998
GObject.ParamFlags.READWRITE | GObject.ParamFlags.EXPLICIT_NOTIFY,
@@ -121,7 +130,8 @@ export const WindowGeometry = GObject.registerClass({
121130
this._workareas_changed_handler =
122131
global.display.connect('workareas-changed', this._update_workarea.bind(this));
123132

124-
this.connect('notify::window-size', this._update_target_rect.bind(this));
133+
this.connect('notify::window-hsize', this._update_target_rect.bind(this));
134+
this.connect('notify::window-vsize', this._update_target_rect.bind(this));
125135
this.connect('notify::window-position', this._update_window_position.bind(this));
126136
this.connect('notify::window-monitor', this.update_monitor.bind(this));
127137
this.connect('notify::window-monitor-connector', this.update_monitor.bind(this));
@@ -137,29 +147,33 @@ export const WindowGeometry = GObject.registerClass({
137147
}
138148
}
139149

140-
static get_target_rect(workarea, monitor_scale, size, window_pos) {
150+
static get_target_rect(workarea, monitor_scale, hsize, vsize, window_pos) {
141151
const target_rect = workarea.copy();
142152

143-
if (window_pos === Meta.Side.LEFT || window_pos === Meta.Side.RIGHT) {
144-
target_rect.width *= size;
145-
target_rect.width -= target_rect.width % monitor_scale;
153+
target_rect.width *= hsize;
154+
target_rect.width -= target_rect.width % monitor_scale;
155+
target_rect.height *= vsize;
156+
target_rect.height -= target_rect.height % monitor_scale;
146157

147-
if (window_pos === Meta.Side.RIGHT)
148-
target_rect.x += workarea.width - target_rect.width;
149-
} else {
150-
target_rect.height *= size;
151-
target_rect.height -= target_rect.height % monitor_scale;
158+
if (window_pos === Meta.Side.RIGHT)
159+
target_rect.x += workarea.width - target_rect.width;
152160

153-
if (window_pos === Meta.Side.BOTTOM)
154-
target_rect.y += workarea.height - target_rect.height;
155-
}
161+
if (window_pos === Meta.Side.BOTTOM)
162+
target_rect.y += workarea.height - target_rect.height;
163+
164+
if (window_pos === Meta.Side.TOP || window_pos === Meta.Side.BOTTOM)
165+
target_rect.x = (workarea.width - target_rect.width) / 2;
166+
167+
if (window_pos === Meta.Side.LEFT || window_pos === Meta.Side.RIGHT)
168+
target_rect.y = (workarea.height - target_rect.height) / 2;
156169

157170
return target_rect;
158171
}
159172

160173
bind_settings(settings) {
161174
[
162-
'window-size',
175+
'window-hsize',
176+
'window-vsize',
163177
'window-position',
164178
'window-monitor',
165179
'window-monitor-connector',
@@ -334,7 +348,8 @@ export const WindowGeometry = GObject.registerClass({
334348
const target_rect = WindowGeometry.get_target_rect(
335349
this._workarea,
336350
Math.floor(global.display.get_monitor_scale(this._monitor_index)),
337-
this.window_size,
351+
this.window_hsize,
352+
this.window_vsize,
338353
this.window_position
339354
);
340355

ddterm/shell/wm.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ export const WindowManager = GObject.registerClass({
9393
this._settings_handlers = Object.entries({
9494
'changed::window-above': this._set_window_above.bind(this),
9595
'changed::window-stick': this._set_window_stick.bind(this),
96-
'changed::window-size': this._disable_window_maximize_setting.bind(this),
96+
'changed::window-hsize': this._disable_window_maximize_setting.bind(this),
97+
'changed::window-vsize': this._disable_window_maximize_setting.bind(this),
9798
'changed::window-maximize': this._set_window_maximized.bind(this),
9899
'changed::override-window-animation': this._setup_animation_overrides.bind(this),
99100
'changed::show-animation': this._update_show_animation.bind(this),
@@ -587,11 +588,11 @@ export const WindowManager = GObject.registerClass({
587588
this.debug?.('Updating size setting on grab end');
588589

589590
const frame_rect = win.get_frame_rect();
590-
const size = this.geometry.orientation === Clutter.Orientation.HORIZONTAL
591-
? frame_rect.width / this.geometry.workarea.width
592-
: frame_rect.height / this.geometry.workarea.height;
591+
const hsize = frame_rect.width / this.geometry.workarea.width;
592+
const vsize = frame_rect.height / this.geometry.workarea.height;
593593

594-
this.settings.set_double('window-size', Math.min(1.0, size));
594+
this.settings.set_double('window-hsize', Math.min(1.0, hsize));
595+
this.settings.set_double('window-vsize', Math.min(1.0, vsize));
595596
}
596597

597598
unmaximize_for_resize(flags) {
@@ -604,7 +605,8 @@ export const WindowManager = GObject.registerClass({
604605

605606
// There is a _update_window_geometry() call after successful unmaximize.
606607
// It must set window size to 100%.
607-
this.settings.set_double('window-size', 1.0);
608+
this.settings.set_double('window-hsize', 1.0);
609+
this.settings.set_double('window-vsize', 1.0);
608610

609611
Main.wm.skipNextEffect(this.window.get_compositor_private());
610612
this.window.unmaximize(flags);

schemas/com.github.amezin.ddterm.gschema.xml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@
132132
</enum>
133133

134134
<schema path="/com/github/amezin/ddterm/" id="com.github.amezin.ddterm">
135-
<key name="window-size" type="d">
135+
<key name="window-hsize" type="d">
136+
<default>1</default>
137+
<range min="0.0" max="1.0"/>
138+
</key>
139+
<key name="window-vsize" type="d">
136140
<default>0.6</default>
137141
<range min="0.0" max="1.0"/>
138142
</key>
@@ -384,10 +388,16 @@
384388
<key name="shortcut-window-hide" type="as">
385389
<default><![CDATA[[]]]></default>
386390
</key>
387-
<key name="shortcut-window-size-inc" type="as">
391+
<key name="shortcut-window-hsize-inc" type="as">
392+
<default><![CDATA[['<Ctrl>Down']]]></default>
393+
</key>
394+
<key name="shortcut-window-hsize-dec" type="as">
395+
<default><![CDATA[['<Ctrl>Up']]]></default>
396+
</key>
397+
<key name="shortcut-window-vsize-inc" type="as">
388398
<default><![CDATA[['<Ctrl>Down']]]></default>
389399
</key>
390-
<key name="shortcut-window-size-dec" type="as">
400+
<key name="shortcut-window-vsize-dec" type="as">
391401
<default><![CDATA[['<Ctrl>Up']]]></default>
392402
</key>
393403
<key name="shortcut-background-opacity-inc" type="as">

0 commit comments

Comments
 (0)