Skip to content

Commit 428655a

Browse files
author
yaoyaozijing
committed
修复Linux「使用系统标题栏」问题,实现设置联动
1 parent 4747fa8 commit 428655a

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

lib/pages/settings/theme_settings_page.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import 'package:kazumi/bean/settings/color_type.dart';
1313
import 'package:kazumi/utils/utils.dart';
1414
import 'package:card_settings_ui/card_settings_ui.dart';
1515
import 'package:provider/provider.dart';
16+
import 'package:path_provider/path_provider.dart';
17+
1618

1719
class ThemeSettingsPage extends StatefulWidget {
1820
const ThemeSettingsPage({super.key});
@@ -372,6 +374,16 @@ class _ThemeSettingsPageState extends State<ThemeSettingsPage> {
372374
SettingsTile.switchTile(
373375
onToggle: (value) async {
374376
showWindowButton = value ?? !showWindowButton;
377+
if(Platform.isLinux){
378+
final directory = await getApplicationSupportDirectory();
379+
final path = directory.path;
380+
final showSystemTitlebar =File('$path/showSystemTitlebar');
381+
if (showWindowButton) {
382+
await showSystemTitlebar.writeAsString('true');
383+
} else {
384+
await showSystemTitlebar.writeAsString('false');
385+
}
386+
}
375387
await setting.put(
376388
SettingBoxKey.showWindowButton, showWindowButton);
377389
setState(() {});

linux/my_application.cc

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
#include "flutter/generated_plugin_registrant.h"
99

10+
#include <fstream>
11+
#include <string>
12+
1013
struct _MyApplication {
1114
GtkApplication parent_instance;
1215
char** dart_entrypoint_arguments;
@@ -38,16 +41,35 @@ static void intent_method_call_handler(FlMethodChannel* channel,
3841
}
3942
}
4043

44+
static bool ReadShowSystemTitlebar() {
45+
const char* home = getenv("HOME");
46+
if (!home) return false;
47+
48+
std::string filepath = std::string(home) + "/.local/share/io.github.Predidit.Kazumi/showSystemTitlebar";
49+
50+
std::ifstream file(filepath);
51+
if (!file.is_open()) return false;
52+
53+
std::string content;
54+
std::getline(file, content);
55+
file.close();
56+
57+
if (content == "true") return true;
58+
if (content == "false") return false;
59+
60+
return false; // 默认值
61+
}
62+
4163
// Implements GApplication::activate.
4264
static void my_application_activate(GApplication* application) {
4365
MyApplication* self = MY_APPLICATION(application);
4466
GtkWindow* window =
4567
GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
4668

47-
// If have GTK_CSD in env and it is equal to 1 then add the gtk header bar
48-
// to always use client side decorations
49-
const char* GTK_CSD = getenv("GTK_CSD");
50-
if (GTK_CSD && strcmp(GTK_CSD, "1") == 0) {
69+
70+
// 根据文件决定是否显示系统标题栏
71+
bool showSystemTitlebar = ReadShowSystemTitlebar();
72+
if (!showSystemTitlebar) {
5173
GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
5274
gtk_widget_show(GTK_WIDGET(header_bar));
5375
gtk_header_bar_set_title(header_bar, "kazumi");

0 commit comments

Comments
 (0)