diff --git a/CHANGELOG.md b/CHANGELOG.md index f4899163..e197df9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - 默认开启,可在设置 -> 窗口中关闭。 - app: 桌面平台支持窗口居中。 - 默认关闭,可在设置 -> 窗口中开启。 +- app: 在linux上通过`XDG_CURRENT_DESKTOP`检查是否位于平铺窗管环境中,如果是,不再记录窗口大小和位置。 - 登录:在登录界面显示注册账户的跳转链接。 - 历史:新增帖子浏览记录。 - 记录帖子名称、浏览的用户,帖子所在分区以及浏览时间。 diff --git a/lib/app.dart b/lib/app.dart index b5dfd554..a962b777 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -219,7 +219,7 @@ class _AppState extends State with WindowListener { @override Future onWindowMove() async { super.onWindowMove(); - if (isDesktop) { + if (isDesktop && !cmdArgs.noWindowChangeRecords) { _windowPosition = await windowManager.getPosition(); setupWindowPositionTimer(); } @@ -228,7 +228,7 @@ class _AppState extends State with WindowListener { @override Future onWindowResize() async { super.onWindowResize(); - if (isDesktop) { + if (isDesktop && !cmdArgs.noWindowChangeRecords) { _windowSize = await windowManager.getSize(); setupWindowSizeTimer(); } diff --git a/lib/cmd.dart b/lib/cmd.dart index 952d965b..8e414dae 100644 --- a/lib/cmd.dart +++ b/lib/cmd.dart @@ -1,6 +1,17 @@ +import 'dart:io' if (dart.libaray.js) 'package:web/web.dart'; + import 'package:args/args.dart'; import 'package:tsdm_client/instance.dart'; +const _linuxTilingWindowManagers = [ + 'bspwm', + 'dwm', + 'hyprland', + 'i3wm', + 'niri', + 'sway', +]; + /// All flags in cmdline. abstract class Flags { /// Disable window related configs, including window size, window title and @@ -8,6 +19,12 @@ abstract class Flags { /// /// Set to false if needed, as in recovery mode. static const noWindowConfigs = 'no-window-configs'; + + /// Disable recoding window status changes, including: + /// + /// * Window size changes. + /// * Window position changes. + static const noWindowChangeRecords = 'no-window-change-records'; } /// Cmdline arguments parsed result. @@ -15,6 +32,7 @@ class CmdArgs { /// Constructor. const CmdArgs({ required this.noWindowConfigs, + required this.noWindowChangeRecords, }); /// Disable window related configs. @@ -22,14 +40,41 @@ class CmdArgs { /// Set to `true` will disable window_manager related features. /// Also the **ONLY** way to disable it. final bool noWindowConfigs; + + /// Disable recording window state changes. + /// + /// Set to `true` will stop recoding window state change features, window size + /// and window position in config storage no longer updates. + final bool noWindowChangeRecords; } /// Parse cmdline [args] into global variable [cmdArgs]. void parseCmdArgs(List args) { - final parser = ArgParser()..addFlag(Flags.noWindowConfigs, negatable: false); - + final parser = ArgParser() + ..addFlag(Flags.noWindowConfigs, negatable: false) + ..addFlag(Flags.noWindowChangeRecords, negatable: false); final argsResult = parser.parse(args); + + var noWindowConfig = argsResult.flag(Flags.noWindowConfigs); + var noWindowChangeRecords = argsResult.flag(Flags.noWindowChangeRecords); + + final envInTilingWindowManager = _linuxTilingWindowManagers + .contains(Platform.environment['XDG_CURRENT_DESKTOP']); + + if (Platform.isLinux && !noWindowConfig && envInTilingWindowManager) { + talker.debug('set no-window-configs to true due to ENV ' + 'detected as tiling window manager'); + noWindowConfig = true; + } + + if (Platform.isLinux && !noWindowChangeRecords && envInTilingWindowManager) { + talker.debug('set no-window-change-records to true due to ENV ' + 'detected as tiling window manager'); + noWindowChangeRecords = true; + } + cmdArgs = CmdArgs( - noWindowConfigs: argsResult.flag(Flags.noWindowConfigs), + noWindowConfigs: noWindowConfig, + noWindowChangeRecords: noWindowChangeRecords, ); }