Initialized burrow-gtk project
This commit is contained in:
parent
759311e4f4
commit
7eec6e73c4
26 changed files with 1534 additions and 1 deletions
92
burrow-gtk/src/application.rs
Normal file
92
burrow-gtk/src/application.rs
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
use gtk::prelude::*;
|
||||
use adw::subclass::prelude::*;
|
||||
use gtk::{gio, glib};
|
||||
|
||||
use crate::config::VERSION;
|
||||
use crate::BurrowGtkWindow;
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct BurrowGtkApplication {}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for BurrowGtkApplication {
|
||||
const NAME: &'static str = "BurrowGtkApplication";
|
||||
type Type = super::BurrowGtkApplication;
|
||||
type ParentType = adw::Application;
|
||||
}
|
||||
|
||||
impl ObjectImpl for BurrowGtkApplication {
|
||||
fn constructed(&self) {
|
||||
self.parent_constructed();
|
||||
let obj = self.obj();
|
||||
obj.setup_gactions();
|
||||
obj.set_accels_for_action("app.quit", &["<primary>q"]);
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationImpl for BurrowGtkApplication {
|
||||
// We connect to the activate callback to create a window when the application
|
||||
// has been launched. Additionally, this callback notifies us when the user
|
||||
// tries to launch a "second instance" of the application. When they try
|
||||
// to do that, we'll just present any existing window.
|
||||
fn activate(&self) {
|
||||
let application = self.obj();
|
||||
// Get the current window or create one if necessary
|
||||
let window = if let Some(window) = application.active_window() {
|
||||
window
|
||||
} else {
|
||||
let window = BurrowGtkWindow::new(&*application);
|
||||
window.upcast()
|
||||
};
|
||||
|
||||
// Ask the window manager/compositor to present the window
|
||||
window.present();
|
||||
}
|
||||
}
|
||||
|
||||
impl GtkApplicationImpl for BurrowGtkApplication {}
|
||||
impl AdwApplicationImpl for BurrowGtkApplication {}
|
||||
}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct BurrowGtkApplication(ObjectSubclass<imp::BurrowGtkApplication>)
|
||||
@extends gio::Application, gtk::Application, adw::Application,
|
||||
@implements gio::ActionGroup, gio::ActionMap;
|
||||
}
|
||||
|
||||
impl BurrowGtkApplication {
|
||||
pub fn new(application_id: &str, flags: &gio::ApplicationFlags) -> Self {
|
||||
glib::Object::builder()
|
||||
.property("application-id", application_id)
|
||||
.property("flags", flags)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn setup_gactions(&self) {
|
||||
let quit_action = gio::ActionEntry::builder("quit")
|
||||
.activate(move |app: &Self, _, _| app.quit())
|
||||
.build();
|
||||
let about_action = gio::ActionEntry::builder("about")
|
||||
.activate(move |app: &Self, _, _| app.show_about())
|
||||
.build();
|
||||
self.add_action_entries([quit_action, about_action]);
|
||||
}
|
||||
|
||||
fn show_about(&self) {
|
||||
let window = self.active_window().unwrap();
|
||||
let about = adw::AboutWindow::builder()
|
||||
.transient_for(&window)
|
||||
.application_name("burrow-gtk")
|
||||
.application_icon("com.hackclub.Burrow")
|
||||
.developer_name("Hack Club")
|
||||
.version(VERSION)
|
||||
.developers(vec!["Hack Club"])
|
||||
.copyright("© 2023 The Hack Foundation")
|
||||
.build();
|
||||
|
||||
about.present();
|
||||
}
|
||||
}
|
||||
7
burrow-gtk/src/burrow-gtk.gresource.xml
Normal file
7
burrow-gtk/src/burrow-gtk.gresource.xml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/com/hackclub/Burrow">
|
||||
<file preprocess="xml-stripblanks">window.ui</file>
|
||||
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
4
burrow-gtk/src/config.rs
Normal file
4
burrow-gtk/src/config.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
pub static VERSION: &str = "0.1.0";
|
||||
pub static GETTEXT_PACKAGE: &str = "burrow-gtk";
|
||||
pub static LOCALEDIR: &str = "/app/share/locale";
|
||||
pub static PKGDATADIR: &str = "/app/share/burrow-gtk";
|
||||
4
burrow-gtk/src/config.rs.in
Normal file
4
burrow-gtk/src/config.rs.in
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
pub static VERSION: &str = @VERSION@;
|
||||
pub static GETTEXT_PACKAGE: &str = @GETTEXT_PACKAGE@;
|
||||
pub static LOCALEDIR: &str = @LOCALEDIR@;
|
||||
pub static PKGDATADIR: &str = @PKGDATADIR@;
|
||||
24
burrow-gtk/src/gtk/help-overlay.blp
Normal file
24
burrow-gtk/src/gtk/help-overlay.blp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
ShortcutsWindow help_overlay {
|
||||
modal: true;
|
||||
|
||||
ShortcutsSection {
|
||||
section-name: "shortcuts";
|
||||
max-height: 10;
|
||||
|
||||
ShortcutsGroup {
|
||||
title: C_("shortcut window", "General");
|
||||
|
||||
ShortcutsShortcut {
|
||||
title: C_("shortcut window", "Show Shortcuts");
|
||||
action-name: "win.show-help-overlay";
|
||||
}
|
||||
|
||||
ShortcutsShortcut {
|
||||
title: C_("shortcut window", "Quit");
|
||||
action-name: "app.quit";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
35
burrow-gtk/src/main.rs
Normal file
35
burrow-gtk/src/main.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
mod application;
|
||||
mod config;
|
||||
mod window;
|
||||
|
||||
use self::application::BurrowGtkApplication;
|
||||
use self::window::BurrowGtkWindow;
|
||||
|
||||
use config::{GETTEXT_PACKAGE, LOCALEDIR, PKGDATADIR};
|
||||
use gettextrs::{bind_textdomain_codeset, bindtextdomain, textdomain};
|
||||
use gtk::{gio, glib};
|
||||
use gtk::prelude::*;
|
||||
|
||||
fn main() -> glib::ExitCode {
|
||||
// Set up gettext translations
|
||||
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR).expect("Unable to bind the text domain");
|
||||
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8")
|
||||
.expect("Unable to set the text domain encoding");
|
||||
textdomain(GETTEXT_PACKAGE).expect("Unable to switch to the text domain");
|
||||
|
||||
// Load resources
|
||||
let resources = gio::Resource::load(PKGDATADIR.to_owned() + "/burrow-gtk.gresource")
|
||||
.expect("Could not load resources");
|
||||
gio::resources_register(&resources);
|
||||
|
||||
// Create a new GtkApplication. The application manages our main loop,
|
||||
// application windows, integration with the window manager/compositor, and
|
||||
// desktop features such as file opening and single-instance applications.
|
||||
let app = BurrowGtkApplication::new("com.hackclub.Burrow", &gio::ApplicationFlags::empty());
|
||||
|
||||
// Run the application. This function will block until the application
|
||||
// exits. Upon return, we have our exit code to return to the shell. (This
|
||||
// is the code you see when you do `echo $?` after running a command in a
|
||||
// terminal.
|
||||
app.run()
|
||||
}
|
||||
67
burrow-gtk/src/meson.build
Normal file
67
burrow-gtk/src/meson.build
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
|
||||
gnome = import('gnome')
|
||||
|
||||
|
||||
blueprints = custom_target('blueprints',
|
||||
input: files(
|
||||
'gtk/help-overlay.blp',
|
||||
'window.blp',
|
||||
),
|
||||
output: '.',
|
||||
command: [find_program('blueprint-compiler'), 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'],
|
||||
)
|
||||
|
||||
gnome.compile_resources('burrow-gtk',
|
||||
'burrow-gtk.gresource.xml',
|
||||
gresource_bundle: true,
|
||||
install: true,
|
||||
install_dir: pkgdatadir,
|
||||
dependencies: blueprints
|
||||
)
|
||||
|
||||
conf = configuration_data()
|
||||
conf.set_quoted('VERSION', meson.project_version())
|
||||
conf.set_quoted('GETTEXT_PACKAGE', 'burrow-gtk')
|
||||
conf.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
|
||||
conf.set_quoted('PKGDATADIR', pkgdatadir)
|
||||
|
||||
configure_file(
|
||||
input: 'config.rs.in',
|
||||
output: 'config.rs',
|
||||
configuration: conf
|
||||
)
|
||||
|
||||
# Copy the config.rs output to the source directory.
|
||||
run_command(
|
||||
'cp',
|
||||
join_paths(meson.project_build_root(), 'src', 'config.rs'),
|
||||
join_paths(meson.project_source_root(), 'src', 'config.rs'),
|
||||
check: true
|
||||
)
|
||||
|
||||
cargo_bin = find_program('cargo')
|
||||
cargo_opt = [ '--manifest-path', meson.project_source_root() / 'Cargo.toml' ]
|
||||
cargo_opt += [ '--target-dir', meson.project_build_root() / 'src' ]
|
||||
cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ]
|
||||
|
||||
if get_option('buildtype') == 'release'
|
||||
cargo_options += [ '--release' ]
|
||||
rust_target = 'release'
|
||||
else
|
||||
rust_target = 'debug'
|
||||
endif
|
||||
|
||||
cargo_build = custom_target(
|
||||
'cargo-build',
|
||||
build_by_default: true,
|
||||
build_always_stale: true,
|
||||
output: meson.project_name(),
|
||||
console: true,
|
||||
install: true,
|
||||
install_dir: get_option('bindir'),
|
||||
command: [
|
||||
'env', cargo_env,
|
||||
cargo_bin, 'build',
|
||||
cargo_opt, '&&', 'cp', 'src' / rust_target / meson.project_name(), '@OUTPUT@',
|
||||
]
|
||||
)
|
||||
48
burrow-gtk/src/window.blp
Normal file
48
burrow-gtk/src/window.blp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using Gtk 4.0;
|
||||
using Adw 1;
|
||||
|
||||
template BurrowGtkWindow : Adw.ApplicationWindow {
|
||||
default-width: 600;
|
||||
default-height: 400;
|
||||
|
||||
Box {
|
||||
orientation: vertical;
|
||||
|
||||
HeaderBar header_bar {
|
||||
[end]
|
||||
MenuButton {
|
||||
icon-name: "open-menu-symbolic";
|
||||
menu-model: primary_menu;
|
||||
}
|
||||
}
|
||||
|
||||
Label label {
|
||||
label: "Burrow GNOME";
|
||||
|
||||
vexpand: true;
|
||||
|
||||
styles [
|
||||
"title-1",
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
menu primary_menu {
|
||||
section {
|
||||
item {
|
||||
label: _("_Preferences");
|
||||
action: "app.preferences";
|
||||
}
|
||||
|
||||
item {
|
||||
label: _("_Keyboard Shortcuts");
|
||||
action: "win.show-help-overlay";
|
||||
}
|
||||
|
||||
item {
|
||||
label: _("_About Burrow-gtk");
|
||||
action: "app.about";
|
||||
}
|
||||
}
|
||||
}
|
||||
51
burrow-gtk/src/window.rs
Normal file
51
burrow-gtk/src/window.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
use gtk::prelude::*;
|
||||
use adw::subclass::prelude::*;
|
||||
use gtk::{gio, glib};
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Default, gtk::CompositeTemplate)]
|
||||
#[template(resource = "/com/hackclub/Burrow/window.ui")]
|
||||
pub struct BurrowGtkWindow {
|
||||
// Template widgets
|
||||
#[template_child]
|
||||
pub header_bar: TemplateChild<gtk::HeaderBar>,
|
||||
#[template_child]
|
||||
pub label: TemplateChild<gtk::Label>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for BurrowGtkWindow {
|
||||
const NAME: &'static str = "BurrowGtkWindow";
|
||||
type Type = super::BurrowGtkWindow;
|
||||
type ParentType = adw::ApplicationWindow;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
klass.bind_template();
|
||||
}
|
||||
|
||||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
||||
obj.init_template();
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectImpl for BurrowGtkWindow {}
|
||||
impl WidgetImpl for BurrowGtkWindow {}
|
||||
impl WindowImpl for BurrowGtkWindow {}
|
||||
impl ApplicationWindowImpl for BurrowGtkWindow {}
|
||||
impl AdwApplicationWindowImpl for BurrowGtkWindow {}
|
||||
}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct BurrowGtkWindow(ObjectSubclass<imp::BurrowGtkWindow>)
|
||||
@extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, adw::ApplicationWindow, @implements gio::ActionGroup, gio::ActionMap;
|
||||
}
|
||||
|
||||
impl BurrowGtkWindow {
|
||||
pub fn new<P: glib::IsA<gtk::Application>>(application: &P) -> Self {
|
||||
glib::Object::builder()
|
||||
.property("application", application)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue