Skip to content

Commit 926f57e

Browse files
committedDec 14, 2016
Fix #613, explictly maintain ratio
1 parent b5729ed commit 926f57e

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed
 

‎source/gx/terminix/session.d

+67-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import gio.Settings : GSettings = Settings;
2424

2525
import glib.Util;
2626

27+
import gobject.ObjectG;
28+
import gobject.ParamSpec;
2729
import gobject.Value;
2830

2931
import gtk.Application;
@@ -186,7 +188,7 @@ private:
186188
* make it look somewhat attractive on Ubuntu and non Adwaita themes.
187189
*/
188190
Paned createPaned(Orientation orientation) {
189-
Paned result = new Paned(orientation);
191+
Paned result = new TerminalPaned(orientation);
190192
if (Version.checkVersion(3, 16, 0).length == 0) {
191193
result.setWideHandle(gsSettings.getBoolean(SETTINGS_ENABLE_WIDE_HANDLE_KEY));
192194
}
@@ -1193,16 +1195,18 @@ public:
11931195
if (direction == "up" || direction == "left")
11941196
increment = -increment;
11951197
while (parent !is null) {
1196-
Paned paned = cast(Paned) parent;
1198+
TerminalPaned paned = cast(TerminalPaned) parent;
11971199
trace("Testing Paned");
11981200
if (paned !is null) {
11991201
if ((direction == "up" || direction == "down") && paned.getOrientation() == Orientation.VERTICAL) {
12001202
trace("Resizing " ~ direction);
12011203
paned.setPosition(paned.getPosition() + increment);
1204+
paned.updateRatio();
12021205
return;
12031206
} else if ((direction == "left" || direction == "right") && paned.getOrientation() == Orientation.HORIZONTAL) {
12041207
trace("Resizing " ~ direction);
12051208
paned.setPosition(paned.getPosition() + increment);
1209+
paned.updateRatio();
12061210
return;
12071211
}
12081212
}
@@ -1452,6 +1456,67 @@ private:
14521456
immutable bool PANED_RESIZE_MODE = false;
14531457
immutable bool PANED_SHRINK_MODE = false;
14541458

1459+
/**
1460+
* Subclass of Paned that maintains a precise ratio split between
1461+
* children as the Paned is re-size (i.e. resizing the window the Paned is
1462+
* a part of. GTK seems to grow one side versus the other for a slight amount
1463+
* without this compensation in place.
1464+
*/
1465+
class TerminalPaned : Paned {
1466+
1467+
private:
1468+
double ratio = 0.5;
1469+
int lastWidth, lastHeight;
1470+
1471+
void updatePosition(GdkRectangle* rect, Widget) {
1472+
//tracef("TerminalPaned Size allocated, ratio %f", ratio);
1473+
if (getOrientation() == Orientation.HORIZONTAL) {
1474+
if (lastWidth != getAllocatedWidth()) {
1475+
int position = to!int(to!double(getAllocatedWidth()) * ratio);
1476+
setPosition(position);
1477+
//tracef("Position=%d, lastWidth=%d, AllocatedWidth=%d, rect.width=%d", position, lastWidth, getAllocatedWidth(), rect.width);
1478+
lastWidth = getAllocatedWidth();
1479+
1480+
}
1481+
} else {
1482+
if (lastHeight != getAllocatedHeight()) {
1483+
setPosition(to!int(getAllocatedHeight() * ratio));
1484+
lastHeight = getAllocatedHeight();
1485+
}
1486+
}
1487+
}
1488+
1489+
public:
1490+
this(Orientation orientation) {
1491+
super(orientation);
1492+
addOnSizeAllocate(&updatePosition);
1493+
addOnButtonRelease(delegate(Event event, Widget w) {
1494+
updateRatio();
1495+
return false;
1496+
});
1497+
addOnAcceptPosition(delegate(Paned) {
1498+
updateRatio();
1499+
return false;
1500+
});
1501+
}
1502+
1503+
void updateRatio() {
1504+
//trace("Updating ratio");
1505+
double newRatio = ratio;
1506+
if (getOrientation() == Orientation.HORIZONTAL) {
1507+
newRatio = to!double(getChild1().getAllocatedWidth()) / to!double(getAllocatedWidth());
1508+
//tracef("Child1 Width=%d, Paned Width=%d",getChild1().getAllocatedWidth(),getAllocatedWidth());
1509+
} else {
1510+
newRatio = to!double(getChild1().getAllocatedHeight()) / to!double(getHeight());
1511+
//tracef("Child1 Height=%d, Paned Height=%d",getChild1().getAllocatedHeight(),getAllocatedHeight());
1512+
}
1513+
if (newRatio > 0.0 && newRatio < 1.0) {
1514+
ratio = newRatio;
1515+
//tracef("New TerminalPaned ratio %f", ratio);
1516+
}
1517+
}
1518+
}
1519+
14551520
/**
14561521
* used during session serialization to store any width/height/position elements
14571522
* as scaled entities so that if restoring a session in a smaller/larger space

0 commit comments

Comments
 (0)