Skip to content

Commit

Permalink
fix: handy window
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier committed Jan 10, 2025
1 parent c30daee commit e3a6d30
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 69 deletions.
5 changes: 4 additions & 1 deletion lib/chat/bootstrap/bootstrap_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class BootstrapModel extends SafeChangeNotifier {
final Client _client;
final FlutterSecureStorage _secureStorage;

Future<bool> isBootrapNeeded() async {
Future<bool> isBootrapNeeded() async =>
_client.isUnknownSession && _client.encryption!.crossSigning.enabled;

Future<bool> isBootrapNeededFull() async {
if (!_client.encryptionEnabled) return true;
await _client.accountDataLoading;
await _client.userDeviceKeysLoading;
Expand Down
21 changes: 14 additions & 7 deletions lib/chat/view/events/chat_message_bubble.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import '../../chat_model.dart';
import '../chat_avatar.dart';
import '../chat_profile_dialog.dart';
import 'chat_event_status_icon.dart';
import 'chat_html_message.dart';
import 'chat_message_attachment_indicator.dart';
import 'chat_message_bubble_shape.dart';
import 'chat_message_media_avatar.dart';
Expand Down Expand Up @@ -196,13 +197,19 @@ class _ChatMessageBubbleContent extends StatelessWidget {
decoration: TextDecoration.lineThrough,
),
)
: SelectableText.rich(
TextSpan(
style: messageStyle,
text: displayEvent.body,
),
style: messageStyle,
),
: event.isRichMessage
? HtmlMessage(
html: html,
room: timeline.room,
defaultTextColor: context.colorScheme.onSurface,
)
: SelectableText.rich(
TextSpan(
style: messageStyle,
text: displayEvent.body,
),
style: messageStyle,
),
),
const SizedBox(
height: kBigPadding,
Expand Down
12 changes: 8 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';
import 'package:yaru/yaru.dart';
Expand All @@ -12,10 +14,12 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();
} else {
await YaruWindowTitleBar.ensureInitialized();
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
});
if (Platform.isMacOS) {
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
});
}
}

registerDependencies();
Expand Down
60 changes: 10 additions & 50 deletions linux/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
# Project-level configuration.
cmake_minimum_required(VERSION 3.10)
project(runner LANGUAGES CXX)

# The name of the executable created for the application. Change this to change
# the on-disk name of your application.
set(BINARY_NAME "nebuchadnezzar")
# The unique GTK application identifier for this application. See:
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
set(APPLICATION_ID "org.feichtmeier.nebuchadnezzar")
set(APPLICATION_ID "org.feichtmeier.Nebuchadnezzar")

# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
# versions of CMake.
cmake_policy(SET CMP0063 NEW)

set(USE_LIBHANDY ON)

# Load bundled libraries from the lib/ directory relative to the binary.
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")

# Root filesystem for cross-building.
if(FLUTTER_TARGET_PLATFORM_SYSROOT)
set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})
set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
endif()

# Define build configuration options.
# Configure build options.
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Debug" CACHE
STRING "Flutter build mode" FORCE)
Expand All @@ -37,19 +17,16 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
endif()

# Compilation settings that should be applied to most targets.
#
# Be cautious about adding new options here, as plugins use this function by
# default. In most cases, you should add new options to specific targets instead
# of modifying this function.
function(APPLY_STANDARD_SETTINGS TARGET)
target_compile_features(${TARGET} PUBLIC cxx_std_14)
target_compile_options(${TARGET} PRIVATE -Wall -Werror)
target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>")
target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")
endfunction()

# Flutter library and tool build rules.
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")

# Flutter library and tool build rules.
add_subdirectory(${FLUTTER_MANAGED_DIR})

# System-level dependencies.
Expand All @@ -58,27 +35,16 @@ pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)

add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")

# Define the application target. To change its name, change BINARY_NAME above,
# not the value here, or `flutter run` will no longer work.
#
# Any new source files that you add to the application should be added here.
# Application build
add_executable(${BINARY_NAME}
"main.cc"
"my_application.cc"
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
)

# Apply the standard set of build settings. This can be removed for applications
# that need different build settings.
apply_standard_settings(${BINARY_NAME})

# Add dependency libraries. Add any application-specific dependencies here.
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)

# Run the Flutter tool portions of the build. This must not be removed.
add_dependencies(${BINARY_NAME} flutter_assemble)

# Only the install-generated bundle's copy of the executable will launch
# correctly, since the resources must in the right relative locations. To avoid
# people trying to run the unbundled copy, put it in a subdirectory instead of
Expand All @@ -88,11 +54,11 @@ set_target_properties(${BINARY_NAME}
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
)


# Generated plugin build rules, which manage building the plugins and adding
# them to the application.
include(flutter/generated_plugins.cmake)

target_link_libraries(${BINARY_NAME} PRIVATE ${MIMALLOC_LIB})

# === Installation ===
# By default, "installing" just makes a relocatable bundle in the build
Expand All @@ -119,17 +85,11 @@ install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}
install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)

foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
install(FILES "${bundled_library}"
if(PLUGIN_BUNDLED_LIBRARIES)
install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)
endforeach(bundled_library)

# Copy the native assets provided by the build.dart from all packages.
set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/")
install(DIRECTORY "${NATIVE_ASSETS_DIR}"
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)
endif()

# Fully re-copy the assets directory on each build to avoid having stale files
# from a previous install.
Expand All @@ -144,4 +104,4 @@ install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)
endif()
endif()
43 changes: 36 additions & 7 deletions linux/my_application.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "my_application.h"

#include <handy.h>
#include <flutter_linux/flutter_linux.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif

#include "flutter/generated_plugin_registrant.h"

Expand All @@ -14,21 +17,47 @@ G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
// Implements GApplication::activate.
static void my_application_activate(GApplication* application) {
MyApplication* self = MY_APPLICATION(application);
GtkWindow* window = GTK_WINDOW(hdy_application_window_new());
gtk_window_set_application(window, GTK_APPLICATION(application));
GtkWindow* window =
GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));

// Use a header bar when running in GNOME as this is the common style used
// by applications and is the setup most users will be using (e.g. Ubuntu
// desktop).
// If running on X and not using GNOME then just use a traditional title bar
// in case the window manager does more exotic layout, e.g. tiling.
// If running on Wayland assume the header bar will work (may need changing
// if future cases occur).
gboolean use_header_bar = TRUE;
#ifdef GDK_WINDOWING_X11
GdkScreen* screen = gtk_window_get_screen(window);
if (GDK_IS_X11_SCREEN(screen)) {
const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
use_header_bar = FALSE;
}
}
#endif
if (use_header_bar) {

gtk_window_set_default_size(window, 800, 600);
gtk_widget_show(GTK_WIDGET(window));
} else {
gtk_window_set_title(window, "Nebuchadnezzar");
}
GdkGeometry geometry_min;
geometry_min.min_width = 500;
geometry_min.min_height = 700;
gtk_window_set_geometry_hints(window, nullptr, &geometry_min, GDK_HINT_MIN_SIZE);
gtk_window_set_default_size(window, 950, 820);

g_autoptr(FlDartProject) project = fl_dart_project_new();
fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);

FlView* view = fl_view_new(project);
gtk_widget_show(GTK_WIDGET(view));
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));

fl_register_plugins(FL_PLUGIN_REGISTRY(view));

gtk_widget_show(GTK_WIDGET(window));
gtk_widget_show(GTK_WIDGET(view));
gtk_widget_grab_focus(GTK_WIDGET(view));
}

Expand Down Expand Up @@ -91,4 +120,4 @@ MyApplication* my_application_new() {
"application-id", APPLICATION_ID,
"flags", G_APPLICATION_NON_UNIQUE,
nullptr));
}
}

0 comments on commit e3a6d30

Please sign in to comment.