Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3dbd0ca
Add example app
jemishavasoya Nov 28, 2023
6a76e0b
Merge branch 'main' into css_colors-add-example-app-#136217
jemishavasoya Nov 28, 2023
c4a4609
add flutter dependabot
jemishavasoya Nov 28, 2023
03e3117
Merge branch 'css_colors-add-example-app-#136217' of https://github.c…
jemishavasoya Nov 28, 2023
c2f8c73
Linux analyze fix
jemishavasoya Nov 28, 2023
83ab6e1
Revert "Linux analyze fix"
jemishavasoya Nov 28, 2023
426a59d
update dart formate
jemishavasoya Nov 29, 2023
51696de
Merge branch 'main' into css_colors-add-example-app-#136217
jemishavasoya Nov 29, 2023
9cd4781
issue fix
jemishavasoya Nov 30, 2023
be9b446
issue fix
jemishavasoya Nov 30, 2023
79edb03
issue fix
jemishavasoya Nov 30, 2023
a7b5166
Merge branch 'main' into css_colors-add-example-app-#136217
jemishavasoya Nov 30, 2023
701ea41
issue fix
jemishavasoya Nov 30, 2023
b561b1e
Merge branch 'css_colors-add-example-app-#136217' of https://github.c…
jemishavasoya Nov 30, 2023
430502e
issue fix
jemishavasoya Nov 30, 2023
1f256a7
formatted correctly
jemishavasoya Nov 30, 2023
c811a25
Update CHANGELOG.md
jemishavasoya Nov 30, 2023
2dc9eff
Update widget_test.dart
jemishavasoya Nov 30, 2023
5b67030
update version
jemishavasoya Nov 30, 2023
ea19846
issue fix
jemishavasoya Nov 30, 2023
03ce13d
Merge branch 'main' into css_colors-add-example-app-#136217
jemishavasoya Nov 30, 2023
466319d
update path
jemishavasoya Nov 30, 2023
0308c0a
Merge branch 'main' into css_colors-add-example-app-#136217
jemishavasoya Nov 30, 2023
00ce96a
Update CHANGELOG.md
jemishavasoya Nov 30, 2023
e133b51
Merge branch 'css_colors-add-example-app-#136217' of https://github.c…
jemishavasoya Nov 30, 2023
b415ef2
Update CHANGELOG.md
jemishavasoya Nov 30, 2023
5abc886
Merge branch 'main' into css_colors-add-example-app-#136217
jemishavasoya Nov 30, 2023
b3b5971
Merge branch 'main' into css_colors-add-example-app-#136217
jemishavasoya Nov 30, 2023
d3d9b70
Merge branch 'main' into css_colors-add-example-app-#136217
jemishavasoya Dec 1, 2023
5789840
Merge branch 'main' into css_colors-add-example-app-#136217
jemishavasoya Dec 1, 2023
c3e61c6
Merge branch 'main' into css_colors-add-example-app-#136217
jemishavasoya Dec 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
formatted correctly
  • Loading branch information
jemishavasoya committed Nov 30, 2023
commit 1f256a747b37d660db6fcb06f2a18cd16a6d815a
145 changes: 75 additions & 70 deletions packages/css_colors/example/linux/my_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,104 +5,109 @@
#include "my_application.h"

#include <flutter_linux/flutter_linux.h>

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

#include "flutter/generated_plugin_registrant.h"

struct _MyApplication {
GtkApplication parent_instance;
char** dart_entrypoint_arguments;
GtkApplication parent_instance;
char **dart_entrypoint_arguments;
};

G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
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(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;
static void my_application_activate(GApplication *application) {
MyApplication * self = MY_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;
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) {
GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
gtk_widget_show(GTK_WIDGET(header_bar));
gtk_header_bar_set_title(header_bar, "example");
gtk_header_bar_set_show_close_button(header_bar, TRUE);
gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
} else {
gtk_window_set_title(window, "example");
}
if (use_header_bar) {
GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
gtk_widget_show(GTK_WIDGET(header_bar));
gtk_header_bar_set_title(header_bar, "example");
gtk_header_bar_set_show_close_button(header_bar, TRUE);
gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
} else {
gtk_window_set_title(window, "example");
}

gtk_window_set_default_size(window, 1280, 720);
gtk_widget_show(GTK_WIDGET(window));
gtk_window_set_default_size(window, 1280, 720);
gtk_widget_show(GTK_WIDGET(window));

g_autoptr(FlDartProject) project = fl_dart_project_new();
fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
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));
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));
fl_register_plugins(FL_PLUGIN_REGISTRY(view));

gtk_widget_grab_focus(GTK_WIDGET(view));
gtk_widget_grab_focus(GTK_WIDGET(view));
}

// Implements GApplication::local_command_line.
static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) {
MyApplication* self = MY_APPLICATION(application);
// Strip out the first argument as it is the binary name.
self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);

g_autoptr(GError) error = nullptr;
if (!g_application_register(application, nullptr, &error)) {
g_warning("Failed to register: %s", error->message);
*exit_status = 1;
return TRUE;
}

g_application_activate(application);
*exit_status = 0;

return TRUE;
static gboolean
my_application_local_command_line(GApplication *application, gchar ***arguments, int *exit_status) {
MyApplication * self = MY_APPLICATION(application);
// Strip out the first argument as it is the binary name.
self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);

g_autoptr(GError)
error = nullptr;
if (!g_application_register(application, nullptr, &error)) {
g_warning("Failed to register: %s", error->message);
*exit_status = 1;
return TRUE;
}

g_application_activate(application);
*exit_status = 0;

return TRUE;
}

// Implements GObject::dispose.
static void my_application_dispose(GObject* object) {
MyApplication* self = MY_APPLICATION(object);
g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
G_OBJECT_CLASS(my_application_parent_class)->dispose(object);
static void my_application_dispose(GObject *object) {
MyApplication * self = MY_APPLICATION(object);
g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
G_OBJECT_CLASS(my_application_parent_class)->dispose(object);
}

static void my_application_class_init(MyApplicationClass* klass) {
G_APPLICATION_CLASS(klass)->activate = my_application_activate;
G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
static void my_application_class_init(MyApplicationClass *klass) {
G_APPLICATION_CLASS(klass)->activate = my_application_activate;
G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
}

static void my_application_init(MyApplication* self) {}
static void my_application_init(MyApplication * self) {}

MyApplication* my_application_new() {
return MY_APPLICATION(g_object_new(my_application_get_type(),
"application-id", APPLICATION_ID,
"flags", G_APPLICATION_NON_UNIQUE,
nullptr));
MyApplication *my_application_new() {
return MY_APPLICATION(g_object_new(my_application_get_type(),
"application-id", APPLICATION_ID,
"flags", G_APPLICATION_NON_UNIQUE,
nullptr));
}
99 changes: 52 additions & 47 deletions packages/css_colors/example/windows/runner/flutter_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,73 @@

#include "flutter/generated_plugin_registrant.h"

FlutterWindow::FlutterWindow(const flutter::DartProject& project)
: project_(project) {}
FlutterWindow::FlutterWindow(const flutter::DartProject &project)
: project_(project) {}

FlutterWindow::~FlutterWindow() {}

bool FlutterWindow::OnCreate() {
if (!Win32Window::OnCreate()) {
return false;
}

RECT frame = GetClientArea();

// The size here must match the window dimensions to avoid unnecessary surface
// creation / destruction in the startup path.
flutter_controller_ = std::make_unique<flutter::FlutterViewController>(
frame.right - frame.left, frame.bottom - frame.top, project_);
// Ensure that basic setup of the controller was successful.
if (!flutter_controller_->engine() || !flutter_controller_->view()) {
return false;
}
RegisterPlugins(flutter_controller_->engine());
SetChildContent(flutter_controller_->view()->GetNativeWindow());

flutter_controller_->engine()->SetNextFrameCallback([&]() {
this->Show();
});

// Flutter can complete the first frame before the "show window" callback is
// registered. The following call ensures a frame is pending to ensure the
// window is shown. It is a no-op if the first frame hasn't completed yet.
flutter_controller_->ForceRedraw();

return true;
if (!Win32Window::OnCreate()) {
return false;
}

RECT frame = GetClientArea();

// The size here must match the window dimensions to avoid unnecessary surface
// creation / destruction in the startup path.
flutter_controller_ = std::make_unique<flutter::FlutterViewController>(
frame.right - frame.left, frame.bottom - frame.top, project_);
// Ensure that basic setup of the controller was successful.
if (!flutter_controller_->engine() || !flutter_controller_->view()) {
return false;
}
RegisterPlugins(flutter_controller_->engine());
SetChildContent(flutter_controller_->view()->GetNativeWindow());

flutter_controller_->engine()->SetNextFrameCallback([&]() {
this->Show();
});

// Flutter can complete the first frame before the "show window" callback is
// registered. The following call ensures a frame is pending to ensure the
// window is shown. It is a no-op if the first frame hasn't completed yet.
flutter_controller_->ForceRedraw();

return true;
}

void FlutterWindow::OnDestroy() {
if (flutter_controller_) {
flutter_controller_ = nullptr;
}
if (flutter_controller_) {
flutter_controller_ = nullptr;
}

Win32Window::OnDestroy();
Win32Window::OnDestroy();
}

LRESULT
FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept {
// Give Flutter, including plugins, an opportunity to handle window messages.
if (flutter_controller_) {
std::optional<LRESULT> result =
LPARAM const lparam)

noexcept {
// Give Flutter, including plugins, an opportunity to handle window messages.
if (flutter_controller_) {
std::optional <LRESULT> result =
flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
lparam);
if (result) {
return *result;
}
}
if (result) {
return *
result;
}
}

switch (message) {
case WM_FONTCHANGE:
flutter_controller_->engine()->ReloadSystemFonts();
break;
}
switch (message) {
case WM_FONTCHANGE:
flutter_controller_->engine()->ReloadSystemFonts();
break;
}

return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
return
Win32Window::MessageHandler(hwnd, message, wparam, lparam
);
}
86 changes: 51 additions & 35 deletions packages/css_colors/example/windows/runner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,55 @@
#include "flutter_window.h"
#include "utils.h"

int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) {
// Attach to console when present (e.g., 'flutter run') or create a
// new console when running with a debugger.
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
CreateAndAttachConsole();
}

// Initialize COM, so that it is available for use in the library and/or
// plugins.
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);

flutter::DartProject project(L"data");

std::vector<std::string> command_line_arguments =
GetCommandLineArguments();

project.set_dart_entrypoint_arguments(std::move(command_line_arguments));

FlutterWindow window(project);
Win32Window::Point origin(10, 10);
Win32Window::Size size(1280, 720);
if (!window.Create(L"example", origin, size)) {
return EXIT_FAILURE;
}
window.SetQuitOnClose(true);

::MSG msg;
while (::GetMessage(&msg, nullptr, 0, 0)) {
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}

::CoUninitialize();
return EXIT_SUCCESS;
int APIENTRY
wWinMain(_In_
HINSTANCE instance, _In_opt_
HINSTANCE prev,
_In_
wchar_t *command_line, _In_
int show_command
) {
// Attach to console when present (e.g., 'flutter run') or create a
// new console when running with a debugger.
if (!
::AttachConsole(ATTACH_PARENT_PROCESS)
&& ::IsDebuggerPresent()) {
CreateAndAttachConsole();

}

// Initialize COM, so that it is available for use in the library and/or
// plugins.
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED
);

flutter::DartProject project(L"data");

std::vector <std::string> command_line_arguments =
GetCommandLineArguments();

project.
set_dart_entrypoint_arguments(std::move(command_line_arguments)
);

FlutterWindow window(project);
Win32Window::Point origin(10, 10);
Win32Window::Size size(1280, 720);
if (!window.Create(L"example", origin, size)) {
return
EXIT_FAILURE;
}
window.SetQuitOnClose(true);

::MSG msg;
while (
::GetMessage(&msg, nullptr,
0, 0)) {
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}

::CoUninitialize();
return
EXIT_SUCCESS;
}
Loading