mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-18 18:51:26 +00:00
calculate new position on display configuration change
This commit is contained in:
@@ -8,9 +8,6 @@
|
||||
******************************************************************************/
|
||||
package org.cryptomator.common.settings;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.Environment;
|
||||
|
||||
import javafx.beans.Observable;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
@@ -23,6 +20,9 @@ import javafx.beans.property.StringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.geometry.NodeOrientation;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.Environment;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Settings {
|
||||
@@ -43,6 +43,8 @@ public class Settings {
|
||||
public static final NodeOrientation DEFAULT_USER_INTERFACE_ORIENTATION = NodeOrientation.LEFT_TO_RIGHT;
|
||||
public static final String DEFAULT_LICENSE_KEY = "";
|
||||
public static final boolean DEFAULT_SHOW_MINIMIZE_BUTTON = false;
|
||||
public static final String DEFAULT_DISPLAY_CONFIGURATION = "";
|
||||
|
||||
|
||||
private final ObservableList<VaultSettings> directories = FXCollections.observableArrayList(VaultSettings::observables);
|
||||
private final BooleanProperty askedForUpdateCheck = new SimpleBooleanProperty(DEFAULT_ASKED_FOR_UPDATE_CHECK);
|
||||
@@ -63,6 +65,7 @@ public class Settings {
|
||||
private final IntegerProperty windowYPosition = new SimpleIntegerProperty();
|
||||
private final IntegerProperty windowWidth = new SimpleIntegerProperty();
|
||||
private final IntegerProperty windowHeight = new SimpleIntegerProperty();
|
||||
private final ObjectProperty<String> displayConfiguration = new SimpleObjectProperty<>(DEFAULT_DISPLAY_CONFIGURATION);
|
||||
|
||||
|
||||
private Consumer<Settings> saveCmd;
|
||||
@@ -92,6 +95,7 @@ public class Settings {
|
||||
windowYPosition.addListener(this::somethingChanged);
|
||||
windowWidth.addListener(this::somethingChanged);
|
||||
windowHeight.addListener(this::somethingChanged);
|
||||
displayConfiguration.addListener(this::somethingChanged);
|
||||
}
|
||||
|
||||
void setSaveCmd(Consumer<Settings> saveCmd) {
|
||||
@@ -183,4 +187,8 @@ public class Settings {
|
||||
public IntegerProperty windowHeightProperty() {
|
||||
return windowHeight;
|
||||
}
|
||||
|
||||
public ObjectProperty<String> displayConfigurationProperty() {
|
||||
return displayConfiguration;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,13 +9,13 @@ import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import javafx.geometry.NodeOrientation;
|
||||
import org.cryptomator.common.Environment;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javafx.geometry.NodeOrientation;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -56,6 +56,7 @@ public class SettingsJsonAdapter extends TypeAdapter<Settings> {
|
||||
out.name("windowYPosition").value((value.windowYPositionProperty().get()));
|
||||
out.name("windowWidth").value((value.windowWidthProperty().get()));
|
||||
out.name("windowHeight").value((value.windowHeightProperty().get()));
|
||||
out.name("displayConfiguration").value((value.displayConfigurationProperty().get()));
|
||||
|
||||
out.endObject();
|
||||
}
|
||||
@@ -95,6 +96,7 @@ public class SettingsJsonAdapter extends TypeAdapter<Settings> {
|
||||
case "windowYPosition" -> settings.windowYPositionProperty().set(in.nextInt());
|
||||
case "windowWidth" -> settings.windowWidthProperty().set(in.nextInt());
|
||||
case "windowHeight"-> settings.windowHeightProperty().set(in.nextInt());
|
||||
case "displayConfiguration" -> settings.displayConfigurationProperty().set(in.nextString());
|
||||
|
||||
default -> {
|
||||
LOG.warn("Unsupported vault setting found in JSON: " + name);
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.awt.*;
|
||||
|
||||
@MainWindow
|
||||
public class ResizeController implements FxController {
|
||||
@@ -63,24 +64,36 @@ public class ResizeController implements FxController {
|
||||
lResizer.setOnMouseDragged(this::resizeLeft);
|
||||
|
||||
window.setHeight(settings.windowHeightProperty().get());
|
||||
//TODO: remove comments
|
||||
//window.setHeight(settings.windowHeightProperty().get() > window.getMaxHeight() ? window.getMaxHeight() * 0.95 : settings.windowHeightProperty().get());
|
||||
|
||||
window.setWidth(settings.windowWidthProperty().get());
|
||||
//window.setWidth(settings.windowWidthProperty().get() > window.getMaxWidth() ? window.getMaxWidth() * 0.95 : settings.windowWidthProperty().get());
|
||||
|
||||
|
||||
//TODO: define illegalPosition
|
||||
boolean illegalPosition = false;
|
||||
if (illegalPosition) {
|
||||
// if the position is illegal, then the window appears on the main screen in the middle of the window.
|
||||
window.setY((window.getMaxHeight() - window.getHeight()) / 2);
|
||||
window.setX((window.getMaxWidth() - window.getWidth()) / 2);
|
||||
if (checkForChangedDisplayConfiguration()) {
|
||||
//If the position is illegal, then the window appears on the main screen in the middle of the window.
|
||||
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
window.setX((size.getWidth() - window.getWidth()) / 2);
|
||||
window.setY((size.getHeight() - window.getHeight()) / 2);
|
||||
} else {
|
||||
window.setX(settings.windowXPositionProperty().get());
|
||||
window.setY(settings.windowYPositionProperty().get());
|
||||
}
|
||||
savePositionalSettings();
|
||||
}
|
||||
|
||||
private boolean checkForChangedDisplayConfiguration(){
|
||||
String currentDisplayConfiguration = getMonitorSizes();
|
||||
boolean changedConfiguration = !settings.displayConfigurationProperty().get().equals(currentDisplayConfiguration);
|
||||
if (changedConfiguration) settings.displayConfigurationProperty().setValue(currentDisplayConfiguration);
|
||||
return changedConfiguration;
|
||||
}
|
||||
|
||||
private String getMonitorSizes() {
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice[] gs = ge.getScreenDevices();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < gs.length; i++) {
|
||||
DisplayMode dm = gs[i].getDisplayMode();
|
||||
sb.append("screenId: " + i + ", " + dm.getWidth() + "x" + dm.getHeight() + "; ");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void startResize(MouseEvent evt) {
|
||||
@@ -93,25 +106,25 @@ public class ResizeController implements FxController {
|
||||
private void resizeTopLeft(MouseEvent evt) {
|
||||
resizeTop(evt);
|
||||
resizeLeft(evt);
|
||||
saveSettings();
|
||||
savePositionalSettings();
|
||||
}
|
||||
|
||||
private void resizeTopRight(MouseEvent evt) {
|
||||
resizeTop(evt);
|
||||
resizeRight(evt);
|
||||
saveSettings();
|
||||
savePositionalSettings();
|
||||
}
|
||||
|
||||
private void resizeBottomLeft(MouseEvent evt) {
|
||||
resizeBottom(evt);
|
||||
resizeLeft(evt);
|
||||
saveSettings();
|
||||
savePositionalSettings();
|
||||
}
|
||||
|
||||
private void resizeBottomRight(MouseEvent evt) {
|
||||
resizeBottom(evt);
|
||||
resizeRight(evt);
|
||||
saveSettings();
|
||||
savePositionalSettings();
|
||||
}
|
||||
|
||||
private void resizeTop(MouseEvent evt) {
|
||||
@@ -148,7 +161,7 @@ public class ResizeController implements FxController {
|
||||
}
|
||||
}
|
||||
|
||||
private void saveSettings() {
|
||||
private void savePositionalSettings() {
|
||||
settings.windowHeightProperty().setValue(window.getHeight());
|
||||
settings.windowWidthProperty().setValue(window.getWidth());
|
||||
settings.windowYPositionProperty().setValue(window.getY());
|
||||
@@ -160,7 +173,7 @@ public class ResizeController implements FxController {
|
||||
}
|
||||
|
||||
public boolean isShowResizingArrows() {
|
||||
//If in fullscreen resizing should not be possible;
|
||||
//If in fullscreen resizing is not be possible;
|
||||
return !window.isFullScreen();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user