Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring window size (width/height) #889

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ddterm/app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,10 @@ class Application extends Gtk.Application {

const shortcut_actions = {
'shortcut-window-hide': 'win.hide',
'shortcut-window-size-inc': 'win.window-size-inc',
'shortcut-window-size-dec': 'win.window-size-dec',
'shortcut-window-hsize-inc': 'win.window-hsize-inc',
'shortcut-window-hsize-dec': 'win.window-hsize-dec',
'shortcut-window-vsize-inc': 'win.window-vsize-inc',
'shortcut-window-vsize-dec': 'win.window-vsize-dec',
'shortcut-background-opacity-inc': 'win.background-opacity-inc',
'shortcut-background-opacity-dec': 'win.background-opacity-dec',
'shortcut-toggle-maximize': 'app.window-maximize',
Expand Down
20 changes: 15 additions & 5 deletions ddterm/app/appwindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,25 @@ class DDTermAppWindow extends Gtk.ApplicationWindow {
'toggle': this.toggle.bind(this),
'show': () => this.present_with_time(Gdk.CURRENT_TIME),
'hide': () => this.hide(),
'window-size-dec': () => {
'window-hsize-dec': () => {
if (this.settings.get_boolean('window-maximize'))
this.settings.set_double('window-size', 1.0 - HEIGHT_MOD);
this.settings.set_double('window-hsize', 1.0 - HEIGHT_MOD);
else
this.adjust_double_setting('window-size', -HEIGHT_MOD);
this.adjust_double_setting('window-hsize', -HEIGHT_MOD);
},
'window-size-inc': () => {
'window-hsize-inc': () => {
if (!this.settings.get_boolean('window-maximize'))
this.adjust_double_setting('window-size', HEIGHT_MOD);
this.adjust_double_setting('window-hsize', HEIGHT_MOD);
},
'window-vsize-dec': () => {
if (this.settings.get_boolean('window-maximize'))
this.settings.set_double('window-vsize', 1.0 - HEIGHT_MOD);
else
this.adjust_double_setting('window-vsize', -HEIGHT_MOD);
},
'window-vsize-inc': () => {
if (!this.settings.get_boolean('window-maximize'))
this.adjust_double_setting('window-vsize', HEIGHT_MOD);
},
'background-opacity-dec': () => {
this.adjust_double_setting('background-opacity', -OPACITY_MOD);
Expand Down
9 changes: 6 additions & 3 deletions ddterm/pref/positionsize.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export const PositionSizeWidget = GObject.registerClass({
Children: [
'monitor_combo',
'window_pos_combo',
'window_size_scale',
'window_hsize_scale',
'window_vsize_scale',
],
Properties: {
'settings': GObject.ParamSpec.object(
Expand Down Expand Up @@ -104,10 +105,12 @@ export const PositionSizeWidget = GObject.registerClass({
this.enable_monitor_combo();

bind_widget(this.settings, 'window-position', this.window_pos_combo);
bind_widget(this.settings, 'window-size', this.window_size_scale);
bind_widget(this.settings, 'window-hsize', this.window_hsize_scale);
bind_widget(this.settings, 'window-vsize', this.window_vsize_scale);

const percent_format = new Intl.NumberFormat(undefined, { style: 'percent' });
set_scale_value_format(this.window_size_scale, percent_format);
set_scale_value_format(this.window_hsize_scale, percent_format);
set_scale_value_format(this.window_vsize_scale, percent_format);
}

get title() {
Expand Down
44 changes: 39 additions & 5 deletions ddterm/pref/ui/prefs-position-size.ui
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ along with ddterm GNOME Shell extension. If not, see <http://www.gnu.org/licens
<!-- interface-license-type gplv3 -->
<!-- interface-name ddterm GNOME Shell extension -->
<!-- interface-copyright 2022 Aleksandr Mezin -->
<object class="GtkAdjustment" id="window_size_adjustment">
<object class="GtkAdjustment" id="window_hsize_adjustment">
<property name="upper">1</property>
<property name="step-increment">0.01</property>
<property name="page-increment">0.10</property>
</object>
<object class="GtkAdjustment" id="window_vsize_adjustment">
<property name="upper">1</property>
<property name="step-increment">0.01</property>
<property name="page-increment">0.10</property>
Expand All @@ -44,21 +49,21 @@ along with ddterm GNOME Shell extension. If not, see <http://www.gnu.org/licens
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Window _size:</property>
<property name="label" translatable="yes">Window _width:</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">window_size_scale</property>
<property name="mnemonic-widget">window_hsize_scale</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">5</property>
</packing>
</child>
<child>
<object class="GtkScale" id="window_size_scale">
<object class="GtkScale" id="window_hsize_scale">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="adjustment">window_size_adjustment</property>
<property name="adjustment">window_hsize_adjustment</property>
<property name="show-fill-level">True</property>
<property name="round-digits">2</property>
<property name="digits">2</property>
Expand All @@ -68,6 +73,35 @@ along with ddterm GNOME Shell extension. If not, see <http://www.gnu.org/licens
<property name="top-attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Window _height:</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">window_vsize_scale</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">6</property>
</packing>
</child>
<child>
<object class="GtkScale" id="window_vsize_scale">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="adjustment">window_vsize_adjustment</property>
<property name="show-fill-level">True</property>
<property name="round-digits">2</property>
<property name="digits">2</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">6</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
Expand Down
22 changes: 18 additions & 4 deletions ddterm/pref/ui/prefs-shortcuts.ui
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,29 @@ along with ddterm GNOME Shell extension. If not, see <http://www.gnu.org/licens
<col id="4">False</col>
</row>
<row>
<col id="0">shortcut-window-size-inc</col>
<col id="1" translatable="yes">Increase Window Size</col>
<col id="0">shortcut-window-hsize-inc</col>
<col id="1" translatable="yes">Increase Horizontal Window Size</col>
<col id="2">0</col>
<col id="3">0</col>
<col id="4">False</col>
</row>
<row>
<col id="0">shortcut-window-size-dec</col>
<col id="1" translatable="yes">Decrease Window Size</col>
<col id="0">shortcut-window-hsize-dec</col>
<col id="1" translatable="yes">Decrease Horizontal Window Size</col>
<col id="2">0</col>
<col id="3">0</col>
<col id="4">False</col>
</row>
<row>
<col id="0">shortcut-window-vsize-inc</col>
<col id="1" translatable="yes">Increase Vertical Window Size</col>
<col id="2">0</col>
<col id="3">0</col>
<col id="4">False</col>
</row>
<row>
<col id="0">shortcut-window-vsize-dec</col>
<col id="1" translatable="yes">Decrease Vertical Window Size</col>
<col id="2">0</col>
<col id="3">0</col>
<col id="4">False</col>
Expand Down
73 changes: 54 additions & 19 deletions ddterm/shell/geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,17 @@ export const WindowGeometry = GObject.registerClass({
Meta.MaximizeFlags,
Meta.MaximizeFlags.VERTICAL
),
'window-size': GObject.ParamSpec.double(
'window-size',
'window-hsize': GObject.ParamSpec.double(
'window-hsize',
'',
'',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.EXPLICIT_NOTIFY,
0,
1,
1
),
'window-vsize': GObject.ParamSpec.double(
'window-vsize',
'',
'',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.EXPLICIT_NOTIFY,
Expand Down Expand Up @@ -121,7 +130,8 @@ export const WindowGeometry = GObject.registerClass({
this._workareas_changed_handler =
global.display.connect('workareas-changed', this._update_workarea.bind(this));

this.connect('notify::window-size', this._update_target_rect.bind(this));
this.connect('notify::window-hsize', this._update_target_rect.bind(this));
this.connect('notify::window-vsize', this._update_target_rect.bind(this));
this.connect('notify::window-position', this._update_window_position.bind(this));
this.connect('notify::window-monitor', this.update_monitor.bind(this));
this.connect('notify::window-monitor-connector', this.update_monitor.bind(this));
Expand All @@ -137,29 +147,33 @@ export const WindowGeometry = GObject.registerClass({
}
}

static get_target_rect(workarea, monitor_scale, size, window_pos) {
static get_target_rect(workarea, monitor_scale, hsize, vsize, window_pos) {
const target_rect = workarea.copy();

if (window_pos === Meta.Side.LEFT || window_pos === Meta.Side.RIGHT) {
target_rect.width *= size;
target_rect.width -= target_rect.width % monitor_scale;
target_rect.width *= hsize;
target_rect.width -= target_rect.width % monitor_scale;
target_rect.height *= vsize;
target_rect.height -= target_rect.height % monitor_scale;

if (window_pos === Meta.Side.RIGHT)
target_rect.x += workarea.width - target_rect.width;
} else {
target_rect.height *= size;
target_rect.height -= target_rect.height % monitor_scale;
if (window_pos === Meta.Side.RIGHT)
target_rect.x += workarea.width - target_rect.width;

if (window_pos === Meta.Side.BOTTOM)
target_rect.y += workarea.height - target_rect.height;
}
if (window_pos === Meta.Side.BOTTOM)
target_rect.y += workarea.height - target_rect.height;

if (window_pos === Meta.Side.TOP || window_pos === Meta.Side.BOTTOM)
target_rect.x = (workarea.width - target_rect.width) / 2;

if (window_pos === Meta.Side.LEFT || window_pos === Meta.Side.RIGHT)
target_rect.y = (workarea.height - target_rect.height) / 2;

return target_rect;
}

bind_settings(settings) {
[
'window-size',
'window-hsize',
'window-vsize',
'window-position',
'window-monitor',
'window-monitor-connector',
Expand Down Expand Up @@ -224,6 +238,16 @@ export const WindowGeometry = GObject.registerClass({
this.notify('pivot-point');
}

_swap_window_sizes() {
var hsize = this.window_hsize;
this.window_hsize = this.window_vsize;
this.window_vsize = hsize;
// TODO: Is this right?
this.notify('window-hsize');
this.notify('window-vsize');
this.notify('target-rect');
}

_set_orientation(new_orientation) {
if (this._orientation === new_orientation)
return;
Expand Down Expand Up @@ -306,14 +330,24 @@ export const WindowGeometry = GObject.registerClass({
switch (this.window_position) {
case Meta.Side.LEFT:
case Meta.Side.RIGHT:
if (this._orientation !== Clutter.Orientation.HORIZONTAL)
this._swap_window_sizes();

this._set_orientation(Clutter.Orientation.HORIZONTAL);
this._set_maximize_flag(Meta.MaximizeFlags.HORIZONTAL);

if (this.window_vsize >= 1.0)
this._set_maximize_flag(Meta.MaximizeFlags.HORIZONTAL);
break;

case Meta.Side.TOP:
case Meta.Side.BOTTOM:
if (this._orientation !== Clutter.Orientation.VERTICAL)
this._swap_window_sizes();

this._set_orientation(Clutter.Orientation.VERTICAL);
this._set_maximize_flag(Meta.MaximizeFlags.VERTICAL);

if (this.window_hsize >= 1.0)
this._set_maximize_flag(Meta.MaximizeFlags.VERTICAL);
}

if (this._orientation === Clutter.Orientation.HORIZONTAL)
Expand All @@ -334,7 +368,8 @@ export const WindowGeometry = GObject.registerClass({
const target_rect = WindowGeometry.get_target_rect(
this._workarea,
Math.floor(global.display.get_monitor_scale(this._monitor_index)),
this.window_size,
this.window_hsize,
this.window_vsize,
this.window_position
);

Expand Down
14 changes: 8 additions & 6 deletions ddterm/shell/wm.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export const WindowManager = GObject.registerClass({
this._settings_handlers = Object.entries({
'changed::window-above': this._set_window_above.bind(this),
'changed::window-stick': this._set_window_stick.bind(this),
'changed::window-size': this._disable_window_maximize_setting.bind(this),
'changed::window-hsize': this._disable_window_maximize_setting.bind(this),
'changed::window-vsize': this._disable_window_maximize_setting.bind(this),
'changed::window-maximize': this._set_window_maximized.bind(this),
'changed::override-window-animation': this._setup_animation_overrides.bind(this),
'changed::show-animation': this._update_show_animation.bind(this),
Expand Down Expand Up @@ -587,11 +588,11 @@ export const WindowManager = GObject.registerClass({
this.debug?.('Updating size setting on grab end');

const frame_rect = win.get_frame_rect();
const size = this.geometry.orientation === Clutter.Orientation.HORIZONTAL
? frame_rect.width / this.geometry.workarea.width
: frame_rect.height / this.geometry.workarea.height;
const hsize = frame_rect.width / this.geometry.workarea.width;
const vsize = frame_rect.height / this.geometry.workarea.height;

this.settings.set_double('window-size', Math.min(1.0, size));
this.settings.set_double('window-hsize', Math.min(1.0, hsize));
this.settings.set_double('window-vsize', Math.min(1.0, vsize));
}

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

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

Main.wm.skipNextEffect(this.window.get_compositor_private());
this.window.unmaximize(flags);
Expand Down
16 changes: 13 additions & 3 deletions schemas/com.github.amezin.ddterm.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@
</enum>

<schema path="/com/github/amezin/ddterm/" id="com.github.amezin.ddterm">
<key name="window-size" type="d">
<key name="window-hsize" type="d">
<default>1</default>
<range min="0.0" max="1.0"/>
</key>
<key name="window-vsize" type="d">
<default>0.6</default>
<range min="0.0" max="1.0"/>
</key>
Expand Down Expand Up @@ -384,10 +388,16 @@
<key name="shortcut-window-hide" type="as">
<default><![CDATA[[]]]></default>
</key>
<key name="shortcut-window-size-inc" type="as">
<key name="shortcut-window-hsize-inc" type="as">
<default><![CDATA[['<Ctrl>Down']]]></default>
</key>
<key name="shortcut-window-hsize-dec" type="as">
<default><![CDATA[['<Ctrl>Up']]]></default>
</key>
<key name="shortcut-window-vsize-inc" type="as">
<default><![CDATA[['<Ctrl>Down']]]></default>
</key>
<key name="shortcut-window-size-dec" type="as">
<key name="shortcut-window-vsize-dec" type="as">
<default><![CDATA[['<Ctrl>Up']]]></default>
</key>
<key name="shortcut-background-opacity-inc" type="as">
Expand Down
Loading
Loading