Skip to content

Commit

Permalink
start Tile library
Browse files Browse the repository at this point in the history
  • Loading branch information
vhdirk committed Jan 29, 2024
1 parent dcec0f7 commit e141e96
Show file tree
Hide file tree
Showing 21 changed files with 316 additions and 161 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ serde = { version = "1.0.196", features = ["derive"] }
once_cell = "1.13.0"
async-channel = "2.1.1"

glib = { version = "^0.18" }
glib = { version = "^0.18", features = ["v2_74"]}
gio = { version = "^0.18" }
pango = { version = "^0.18" }
gdk = { package = "gdk4", version = "^0.7", features = ["v4_12"] }
Expand Down
4 changes: 3 additions & 1 deletion data/resources/resources.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<file compressed="true" preprocess="xml-stripblanks" alias="terminal_tab.ui">../../src/components/terminal_tab/terminal_tab.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="search_toolbar.ui">../../src/components/search_toolbar/search_toolbar.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="style_switcher.ui">../../src/components/style_switcher/style_switcher.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="zoom_controls.ui">../../src/components/zoom_controls/zoom_controls.ui</file>
</gresource>
<gresource prefix="/io/github/vhdirk/Terms/svg">
<file compressed="true" preprocess="xml-stripblanks" alias="theme-thumbnail.svg">svg/theme-thumbnail.svg</file>
Expand All @@ -31,4 +30,7 @@
<file compressed="true" preprocess="xml-stripblanks" alias="app-icon-devel.svg">../icons/io.github.vhdirk.Terms.Devel.svg</file>
<file compressed="true" preprocess="xml-stripblanks" alias="app-icon-symbolic.svg">../icons/io.github.vhdirk.Terms-symbolic.svg</file>
</gresource>
<gresource prefix="/io/github/vhdirk/Tile/gtk">
<file compressed="true" preprocess="xml-stripblanks" alias="zoom_controls.ui">../../src/tile/zoom_controls/zoom_controls.ui</file>
</gresource>
</gresources>
8 changes: 7 additions & 1 deletion data/resources/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ window:not(.about) headerbar,
background-color: @window_bg_color;
}

#terms_tab_bar.integrated {
margin-top: -6px;
margin-bottom: -6px;
}

/* #terms_main_window.context-root .custom-headerbar {
background-color: @root_context_color;
}
Expand All @@ -28,7 +33,8 @@ window:not(.about) headerbar,
/* .custom-headerbar windowhandle>box {
padding-top: 0;
padding-bottom: 0;
}
} */
/*
.custom-headerbar windowcontrols:not(.empty).start {
margin-right: 6px;
Expand Down
4 changes: 3 additions & 1 deletion src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ mod imp {
let app = self.obj();

info!("Window init args: {:?} {:?} {:?}", command, directory, env);
let window = Window::new(&*app, command, directory, env);

let window = Window::new(&*app);
window.new_tab(command, directory, env);

info!("Add window");
app.add_window(&window);
Expand Down
13 changes: 7 additions & 6 deletions src/components/header_bar/header_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use gtk::prelude::*;
use tracing::info;

use crate::components::StyleSwitcher;
use crate::components::ZoomControls;
use crate::settings::Settings;
use crate::tile::ZoomControls;

#[derive(Debug, Default, gtk::CompositeTemplate, Properties)]
#[template(resource = "/io/github/vhdirk/Terms/gtk/header_bar.ui")]
Expand Down Expand Up @@ -148,15 +148,16 @@ impl HeaderBar {
fn set_integrated_tab_bar(&self) {
let tab_bar = self.tab_bar.borrow();

tab_bar.unparent();

if self.settings.headerbar_integrated_tabbar() && tab_bar.view().map_or(false, |view| view.n_pages() > 1) {
self.header_bar.set_title_widget(Some(&*tab_bar));
if self.settings.headerbar_integrated_tabbar() {
if self.header_bar.title_widget() != Some(tab_bar.clone().into()) {
tab_bar.unparent();
self.header_bar.set_title_widget(Some(&*tab_bar));
}
tab_bar.set_halign(gtk::Align::Fill);
tab_bar.set_hexpand(true);
tab_bar.set_autohide(false);
tab_bar.set_can_focus(false);
tab_bar.set_css_classes(&["inline"]);
tab_bar.set_css_classes(&["inline", "integrated"]);
} else {
self.header_bar.set_title_widget(Some(&*self.title_widget));
self.header_box.append(&*tab_bar);
Expand Down
72 changes: 32 additions & 40 deletions src/components/header_bar/header_bar.ui
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<requires lib="gtk" version="4.10" />
<requires lib="libadwaita" version="1.4" />


<menu id='main-menu'>
<section>
<item>
Expand Down Expand Up @@ -72,15 +71,42 @@
<object class="AdwHeaderBar" id="header_bar">
<property name="hexpand">true</property>

<!-- <child type="start"></child> -->
<child type="start">
<object class="GtkBox" id="new_tab_box">
<property name="css-name">splitbutton</property>
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkButton" id="new_terminal_button">
<property name="icon-name">tab-new-symbolic</property>
<property name="tooltip-text" translatable="yes">New Tab</property>
<property name="action-name">win.new-tab</property>
<property name="focus-on-click">false</property>
</object>
</child>
<child>
<object class="GtkSeparator" id="new_terminal_separator">
<property name="orientation">vertical</property>
</object>
</child>
<child>
<object class="GtkMenuButton" id="new_terminal_menu_button">
<child>
<object class="GtkImage">
<property name="icon-name">pan-down-symbolic</property>
</object>
</child>
</object>
</child>
</object>
</child>

<property name="title-widget">
<object class="AdwWindowTitle" id="title_widget">
<property name="visible">true</property>
<property name="title" bind-source="TermsHeaderBar" bind-property="title" bind-flags="sync-create">Terms</property>
</object>


</property>

<child type="end">
Expand All @@ -95,53 +121,19 @@
<object class="TermsStyleSwitcher" id="style_switcher"></object>
</child>
<child type="zoom-controls">
<object class="TermsZoomControls" id="zoom_controls"></object>
<object class="TileZoomControls" id="zoom_controls">
</object>
</child>
</object>
</property>
</object>
</child>

</object>




<!-- <child>
<object class="GtkWindowControls">
<property name="side">end</property>
<!- <binding name="visible">
<closure type="gboolean" function="show_window_controls">
<lookup name="fullscreened">
<lookup name="window">TerminalHeaderBar</lookup>
</lookup>
<lookup name="floating-mode">TerminalHeaderBar</lookup>
<lookup name="single-tab-mode">TerminalHeaderBar</lookup>
<constant type="gboolean">false</constant>
</closure>
</binding> ->
</object>
</child>
</object>
</child> -->
<!-- <object class="AdwHeaderBar">
<property name="hexpand">true</property>
<property name="title-widget">
<object class="AdwWindowTitle" id="title_widget">
<property name="title">Terms</property>
</object>
</property>
-->
</child>

</object>

</child>

</object>
</child>

</template>
</interface>
2 changes: 0 additions & 2 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mod terminal_preferences_page;
mod terminal_tab;
mod theme_thumbnail;
mod window;
mod zoom_controls;

pub use header_bar::*;
pub use preferences_window::*;
Expand All @@ -28,4 +27,3 @@ pub use terminal_preferences_page::*;
pub use terminal_tab::*;
pub use theme_thumbnail::*;
pub use window::*;
pub use zoom_controls::*;
39 changes: 19 additions & 20 deletions src/components/style_switcher/style_switcher.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
/* StyleSwitcher.vala
*
* Copyright 2023 Paulo Queiroz <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

/// This file is work derived from Black Box
///
/// Copyright 2023 Paulo Queiroz <[email protected]>
///
/// This program is free software: you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation, either version 3 of the License, or
/// (at your option) any later version.
///
/// This program is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with this program. If not, see <http://www.gnu.org/licenses/>.
///
/// SPDX-License-Identifier: GPL-3.0-or-later
///
use glib::clone;
use gtk::subclass::prelude::*;
use gtk::{prelude::*, CompositeTemplate};
Expand Down
12 changes: 12 additions & 0 deletions src/components/terminal/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ pub struct Terminal {

#[property(get, set, construct, nullable)]
title: RefCell<Option<String>>,

#[property(get, set, construct, nullable)]
icon: RefCell<Option<String>>,
}

impl Default for Terminal {
Expand All @@ -113,6 +116,8 @@ impl Default for Terminal {
command: Default::default(),
env: Default::default(),
title: Default::default(),
icon: Default::default(),

update_source: Default::default(),
}
}
Expand Down Expand Up @@ -297,7 +302,9 @@ impl Terminal {
if let (Some(match_str), _tag) = this.term.check_match_at(x, y) {
if event.modifier_state().contains(gdk::ModifierType::CONTROL_MASK) {


// TODO: get active window
// TODO: launch through xdg portal on flatpak
glib::spawn_future_local(gtk::UriLauncher::new(&match_str).launch_future(None::<&gtk::Window>));
}
}
Expand Down Expand Up @@ -575,6 +582,11 @@ impl Terminal {

*self.title.borrow_mut() = title;
self.obj().notify_title();

// TODO: icon title. vte icon title is deprecated
// let icon = self.term.icon_title().map(|t| t.to_string());
// *self.icon.borrow_mut() = icon;
// self.obj().notify_icon();
}

fn enqueue_update(&self) {
Expand Down
5 changes: 3 additions & 2 deletions src/components/terminal_panel/terminal_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ pub struct TerminalPanel {

#[property(get, set, construct, nullable)]
title: RefCell<Option<String>>,

#[property(get, set, construct, nullable)]
icon: RefCell<Option<String>>,
}

#[glib::object_subclass]
Expand Down Expand Up @@ -99,5 +102,3 @@ impl TerminalPanel {
// // // </object>
// // // </child>
// // // </template>

// // },
3 changes: 3 additions & 0 deletions src/components/terminal_tab/terminal_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub struct TerminalTab {

#[property(get, set, construct, nullable)]
title: RefCell<Option<String>>,

#[property(get, set, construct, nullable)]
icon: RefCell<Option<String>>,
}

#[glib::object_subclass]
Expand Down
24 changes: 17 additions & 7 deletions src/components/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod window;
use std::path::PathBuf;

use glib::subclass::prelude::*;
use tracing::*;
use window as imp;

use crate::util::EnvMap;
Expand All @@ -15,12 +16,21 @@ glib::wrapper! {
}

impl Window {
pub fn new<P: glib::IsA<gtk::Application>>(application: &P, command: Option<String>, directory: Option<PathBuf>, env: Option<EnvMap>) -> Self {
glib::Object::builder()
.property("application", application)
.property("command", command)
.property("directory", directory)
.property("env", env)
.build()
pub fn new<P: glib::IsA<gtk::Application>>(application: &P) -> Self {
glib::Object::builder().property("application", application).build()
}

pub fn new_tab(&self, command: Option<String>, directory: Option<PathBuf>, env: Option<EnvMap>) {
self.imp().new_tab(command, directory, env);
}

pub fn transfer_tab(&self, view: &adw::TabView, page: &adw::TabPage, position: i32) {
let our_view = &*self.imp().tab_view;
debug!("Transferring tab page {:?} from {:?} to {:?}", page, view, our_view);
view.transfer_page(page, our_view, position);
}

pub fn tab_view(&self) -> Option<adw::TabView> {
self.imp().tab_view.try_get()
}
}
Loading

0 comments on commit e141e96

Please sign in to comment.