Skip to content

Commit

Permalink
feat(linux): disable recording window changes when in tiling wm envir…
Browse files Browse the repository at this point in the history
…onment
  • Loading branch information
realth000 committed Oct 5, 2024
1 parent 581f161 commit 4753d44
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`检查是否位于平铺窗管环境中,如果是,不再记录窗口大小和位置。
- 登录:在登录界面显示注册账户的跳转链接。
- 历史:新增帖子浏览记录。
- 记录帖子名称、浏览的用户,帖子所在分区以及浏览时间。
Expand Down
4 changes: 2 additions & 2 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class _AppState extends State<App> with WindowListener {
@override
Future<void> onWindowMove() async {
super.onWindowMove();
if (isDesktop) {
if (isDesktop && !cmdArgs.noWindowChangeRecords) {
_windowPosition = await windowManager.getPosition();
setupWindowPositionTimer();
}
Expand All @@ -228,7 +228,7 @@ class _AppState extends State<App> with WindowListener {
@override
Future<void> onWindowResize() async {
super.onWindowResize();
if (isDesktop) {
if (isDesktop && !cmdArgs.noWindowChangeRecords) {
_windowSize = await windowManager.getSize();
setupWindowSizeTimer();
}
Expand Down
51 changes: 48 additions & 3 deletions lib/cmd.dart
Original file line number Diff line number Diff line change
@@ -1,35 +1,80 @@
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
/// window position.
///
/// 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.
class CmdArgs {
/// Constructor.
const CmdArgs({
required this.noWindowConfigs,
required this.noWindowChangeRecords,
});

/// Disable window related configs.
///
/// 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<String> 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,
);
}

0 comments on commit 4753d44

Please sign in to comment.