Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
feat: added sessions open/close
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed May 2, 2024
1 parent c9bbef8 commit a37df2a
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 2 deletions.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

src = lib.cleanSource self;

buildInputs = with s; [ pam accountsservice polkit ];
buildInputs = with s; [ pam accountsservice polkit seatd ];

pubspecLock = lib.importJSON ./pubspec.lock.json;

Expand Down
25 changes: 25 additions & 0 deletions lib/views/desktop.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart';

import '../logic/wallpaper.dart';
Expand All @@ -22,6 +23,30 @@ class DesktopView extends StatefulWidget {
}

class _DesktopViewState extends State<DesktopView> {
static const sessionChannel = MethodChannel('com.expidusos.genesis.shell/session');

String? sessionName = null;

@override
void initState() {
super.initState();

sessionChannel.invokeMethod('open').then((name) => setState(() {
sessionName = name;
})).catchError((err) {
print(err);
});
}

@override
void dispose() {
super.dispose();

sessionChannel.invokeMethod('close', sessionName).catchError((err) {
print(err);
});
}

@override
Widget build(BuildContext context) =>
SystemLayout(
Expand Down
9 changes: 8 additions & 1 deletion linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ add_subdirectory(${FLUTTER_MANAGED_DIR})
find_package(PkgConfig REQUIRED)
pkg_check_modules(ACCOUNTSSERVICE REQUIRED IMPORTED_TARGET accountsservice)
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
pkg_check_modules(LIBSEAT REQUIRED IMPORTED_TARGET libseat)
pkg_check_modules(PAM REQUIRED IMPORTED_TARGET pam)

add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
Expand All @@ -68,6 +69,7 @@ add_executable(${BINARY_NAME}
"channels/account.cc"
"channels/auth.cc"
"channels/outputs.cc"
"channels/session.cc"
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
)

Expand All @@ -77,7 +79,12 @@ 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::ACCOUNTSSERVICE PkgConfig::GTK PkgConfig::PAM)
target_link_libraries(${BINARY_NAME} PRIVATE
PkgConfig::ACCOUNTSSERVICE
PkgConfig::GTK
PkgConfig::LIBSEAT
PkgConfig::PAM
)

# Run the Flutter tool portions of the build. This must not be removed.
add_dependencies(${BINARY_NAME} flutter_assemble)
Expand Down
3 changes: 3 additions & 0 deletions linux/application-priv.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma once

#include "channels/session.h"

struct _GenesisShellApplication {
GtkApplication parent_instance;
char** dart_entrypoint_arguments;
FlMethodChannel* outputs;
FlMethodChannel* account;
FlMethodChannel* auth;
SessionChannel session;
GtkWindow* win;
};
3 changes: 3 additions & 0 deletions linux/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static void genesis_shell_application_activate(GApplication* application) {
fl_method_channel_set_method_call_handler(self->auth, auth_method_call_handler, self, nullptr);
}

session_channel_init(&self->session, view);
gtk_widget_grab_focus(GTK_WIDGET(view));
}

Expand Down Expand Up @@ -98,6 +99,8 @@ static void genesis_shell_application_dispose(GObject* object) {
g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
g_clear_object(&self->outputs);
g_clear_object(&self->auth);
g_clear_object(&self->account);
session_channel_deinit(&self->session);
G_OBJECT_CLASS(genesis_shell_application_parent_class)->dispose(object);
}

Expand Down
67 changes: 67 additions & 0 deletions linux/channels/session.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <flutter_linux/flutter_linux.h>

extern "C" {
#include <libseat.h>
}

#include "session.h"
#include "../application-priv.h"

static void handle_enable(struct libseat* backend, void* data) {
(void)backend;
(void)data;
}

static void handle_disable(struct libseat* backend, void* data) {
(void)data;
libseat_disable_seat(backend);
}

struct libseat_seat_listener listener = {
.enable_seat = handle_enable,
.disable_seat = handle_disable,
};

static void method_call_handler(FlMethodChannel* channel, FlMethodCall* method_call, gpointer user_data) {
SessionChannel* self = (SessionChannel*)user_data;
g_autoptr(FlMethodResponse) response = nullptr;

if (strcmp(fl_method_call_get_name(method_call), "open") == 0) {
struct libseat* seat = libseat_open_seat(&listener, user_data);
const char* name = libseat_seat_name(seat);
g_hash_table_insert(self->seats, (gpointer)name, (gpointer)seat);
response = FL_METHOD_RESPONSE(fl_method_success_response_new(fl_value_new_string(name)));
} else if (strcmp(fl_method_call_get_name(method_call), "close") == 0) {
FlValue* args = fl_method_call_get_args(method_call);
const gchar* name = fl_value_get_string(args);

if (g_hash_table_contains(self->seats, name)) {
struct libseat* seat = (struct libseat*)g_hash_table_lookup(self->seats, name);
g_hash_table_remove(self->seats, name);
libseat_close_seat(seat);
response = FL_METHOD_RESPONSE(fl_method_success_response_new(fl_value_new_bool(true)));
} else {
response = FL_METHOD_RESPONSE(fl_method_success_response_new(fl_value_new_bool(false)));
}
} else {
response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
}

g_autoptr(GError) error = nullptr;
if (!fl_method_call_respond(method_call, response, &error)) {
g_warning("Failed to send response: %s", error->message);
}
}

void session_channel_init(SessionChannel* self, FlView* view) {
self->seats = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)libseat_close_seat);

g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
self->channel = fl_method_channel_new(fl_engine_get_binary_messenger(fl_view_get_engine(view)), "com.expidusos.genesis.shell/session", FL_METHOD_CODEC(codec));
fl_method_channel_set_method_call_handler(self->channel, method_call_handler, self, nullptr);
}

void session_channel_deinit(SessionChannel* self) {
g_clear_object(&self->channel);
g_hash_table_unref(self->seats);
}
13 changes: 13 additions & 0 deletions linux/channels/session.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <flutter_linux/flutter_linux.h>

#include "../application.h"

typedef struct _SessionChannel {
GHashTable* seats;
FlMethodChannel* channel;
} SessionChannel;

void session_channel_init(SessionChannel* self, FlView* view);
void session_channel_deinit(SessionChannel* self);

0 comments on commit a37df2a

Please sign in to comment.