diff options
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/astal.vala | 389 | ||||
-rw-r--r-- | core/src/cli.vala | 87 | ||||
-rw-r--r-- | core/src/config.vala.in | 6 | ||||
-rw-r--r-- | core/src/file.vala | 81 | ||||
-rw-r--r-- | core/src/idle-inhibit.c | 114 | ||||
-rw-r--r-- | core/src/idle-inhibit.h | 22 | ||||
-rw-r--r-- | core/src/meson.build | 136 | ||||
-rw-r--r-- | core/src/process.vala | 119 | ||||
-rw-r--r-- | core/src/time.vala | 73 | ||||
-rw-r--r-- | core/src/vapi/AstalInhibitManager.vapi | 13 | ||||
-rw-r--r-- | core/src/variable.vala | 196 | ||||
-rw-r--r-- | core/src/widget/box.vala | 62 | ||||
-rw-r--r-- | core/src/widget/button.vala | 101 | ||||
-rw-r--r-- | core/src/widget/centerbox.vala | 54 | ||||
-rw-r--r-- | core/src/widget/circularprogress.vala | 182 | ||||
-rw-r--r-- | core/src/widget/eventbox.vala | 66 | ||||
-rw-r--r-- | core/src/widget/icon.vala | 107 | ||||
-rw-r--r-- | core/src/widget/label.vala | 18 | ||||
-rw-r--r-- | core/src/widget/levelbar.vala | 15 | ||||
-rw-r--r-- | core/src/widget/overlay.vala | 59 | ||||
-rw-r--r-- | core/src/widget/scrollable.vala | 42 | ||||
-rw-r--r-- | core/src/widget/slider.vala | 73 | ||||
-rw-r--r-- | core/src/widget/stack.vala | 26 | ||||
-rw-r--r-- | core/src/widget/widget.vala | 157 | ||||
-rw-r--r-- | core/src/widget/window.vala | 255 |
25 files changed, 0 insertions, 2453 deletions
diff --git a/core/src/astal.vala b/core/src/astal.vala deleted file mode 100644 index 176062f..0000000 --- a/core/src/astal.vala +++ /dev/null @@ -1,389 +0,0 @@ -namespace Astal { -[DBus (name="io.Astal.Application")] -public class Application : Gtk.Application { - private List<Gtk.CssProvider> css_providers = new List<Gtk.CssProvider>(); - private SocketService service; - private DBusConnection conn; - private string _instance_name; - - public string socket_path { get; private set; } - - [DBus (visible=false)] - public signal void monitor_added(Gdk.Monitor monitor); - - [DBus (visible=false)] - public signal void monitor_removed(Gdk.Monitor monitor); - - [DBus (visible=false)] - public signal void window_toggled(Gtk.Window window); - - [DBus (visible=false)] - public List<weak Gdk.Monitor> monitors { - owned get { - var display = Gdk.Display.get_default(); - var list = new List<weak Gdk.Monitor>(); - for (var i = 0; i <= display.get_n_monitors(); ++i) { - var mon = display.get_monitor(i); - if (mon != null) { - list.append(mon); - } - } - return list; - } - } - - [DBus (visible=false)] - public string instance_name { - get { return _instance_name; } - set { - application_id = "io.Astal." + value; - _instance_name = value; - } - } - - [DBus (visible=false)] - public List<Gtk.Window> windows { - get { return get_windows(); } - } - - [DBus (visible=false)] - public Gtk.Settings settings { - get { return Gtk.Settings.get_default(); } - } - - [DBus (visible=false)] - public Gdk.Screen screen { - get { return Gdk.Screen.get_default(); } - } - - [DBus (visible=false)] - public string gtk_theme { - owned get { return settings.gtk_theme_name; } - set { settings.gtk_theme_name = value; } - } - - [DBus (visible=false)] - public string icon_theme { - owned get { return settings.gtk_icon_theme_name; } - set { settings.gtk_icon_theme_name = value; } - } - - [DBus (visible=false)] - public string cursor_theme { - owned get { return settings.gtk_cursor_theme_name; } - set { settings.gtk_cursor_theme_name = value; } - } - - [DBus (visible=false)] - public void reset_css() { - foreach(var provider in css_providers) { - Gtk.StyleContext.remove_provider_for_screen(screen, provider); - } - css_providers = new List<Gtk.CssProvider>(); - } - - public void inspector() throws DBusError, IOError { - Gtk.Window.set_interactive_debugging(true); - } - - [DBus (visible=false)] - public Gtk.Window? get_window(string name) { - foreach(var win in windows) { - if (win.name == name) - return win; - } - - critical("no window with name \"%s\"".printf(name)); - return null; - } - - public void toggle_window(string window) throws DBusError, IOError { - var win = get_window(window); - if (win != null) { - win.visible = !win.visible; - } else { - throw new IOError.FAILED("window not found"); - } - } - - [DBus (visible=false)] - public void apply_css(string style, bool reset = false) { - var provider = new Gtk.CssProvider(); - - if (reset) - reset_css(); - - try { - if (FileUtils.test(style, FileTest.EXISTS)) - provider.load_from_path(style); - else - provider.load_from_data(style); - } catch (Error err) { - critical(err.message); - } - - Gtk.StyleContext.add_provider_for_screen( - screen, provider, Gtk.STYLE_PROVIDER_PRIORITY_USER); - - css_providers.append(provider); - } - - [DBus (visible=false)] - public void add_icons(string? path) { - if (path != null) - Gtk.IconTheme.get_default().prepend_search_path(path); - } - - private async void _socket_request(SocketConnection conn) { - string message = yield read_sock(conn); - request(message != null ? message.strip() : "", conn); - } - - [DBus (visible=false)] - public virtual void request(string msg, SocketConnection conn) { - write_sock.begin(conn, @"missing response implementation on $application_id"); - } - - /** - * should be called before `run()` - * the return value indicates if instance is already running - */ - [DBus (visible=false)] - public bool acquire_socket() { - foreach (var instance in get_instances()) { - if (instance == instance_name) { - return false; - } - } - - var rundir = GLib.Environment.get_user_runtime_dir(); - socket_path = @"$rundir/$instance_name.sock"; - - if (FileUtils.test(socket_path, GLib.FileTest.EXISTS)) { - try { - File.new_for_path(socket_path).delete(null); - } catch (Error err) { - critical(err.message); - } - } - - try { - service = new SocketService(); - service.add_address( - new UnixSocketAddress(socket_path), - SocketType.STREAM, - SocketProtocol.DEFAULT, - null, - null); - - service.incoming.connect((conn) => { - _socket_request.begin(conn, (_, res) => _socket_request.end(res)); - return false; - }); - - Bus.own_name( - BusType.SESSION, - "io.Astal." + instance_name, - BusNameOwnerFlags.NONE, - (conn) => { - try { - this.conn = conn; - conn.register_object("/io/Astal/Application", this); - } catch (Error err) { - critical(err.message); - } - }, - () => {}, - () => {}); - - info("socket acquired: %s\n", socket_path); - return true; - } catch (Error err) { - critical("could not acquire socket %s\n", application_id); - critical(err.message); - return false; - } - } - - public string message(string? msg) throws DBusError, IOError { - var rundir = GLib.Environment.get_user_runtime_dir(); - var socket_path = @"$rundir/$instance_name.sock"; - var client = new SocketClient(); - - if (msg == null) - msg = ""; - - try { - var conn = client.connect(new UnixSocketAddress(socket_path), null); - conn.output_stream.write(msg.concat("\x04").data); - - var stream = new DataInputStream(conn.input_stream); - return stream.read_upto("\x04", -1, null, null); - } catch (Error err) { - printerr(err.message); - return ""; - } - } - - public new void quit() throws DBusError, IOError { - if (service != null) { - if (FileUtils.test(socket_path, GLib.FileTest.EXISTS)){ - try { - File.new_for_path(socket_path).delete(null); - } catch (Error err) { - warning(err.message); - } - } - } - - base.quit(); - } - - construct { - if (instance_name == null) - instance_name = "astal"; - - activate.connect(() => { - var display = Gdk.Display.get_default(); - display.monitor_added.connect((mon) => { - monitor_added(mon); - notify_property("monitors"); - }); - display.monitor_removed.connect((mon) => { - monitor_removed(mon); - notify_property("monitors"); - }); - }); - - window_added.connect((window) => { - ulong id1, id2; - id1 = window.notify["visible"].connect(() => window_toggled(window)); - id2 = window_removed.connect((removed) => { - if (removed == window) { - window.disconnect(id1); - this.disconnect(id2); - } - }); - }); - - shutdown.connect(() => { try { quit(); } catch(Error err) {} }); - Unix.signal_add(1, () => { try { quit(); } catch(Error err) {} }, Priority.HIGH); - Unix.signal_add(2, () => { try { quit(); } catch(Error err) {} }, Priority.HIGH); - Unix.signal_add(15, () => { try { quit(); } catch(Error err) {} }, Priority.HIGH); - } - - public static List<string> get_instances() { - var list = new List<string>(); - var prefix = "io.Astal."; - - try { - DBusImpl dbus = Bus.get_proxy_sync( - BusType.SESSION, - "org.freedesktop.DBus", - "/org/freedesktop/DBus" - ); - - foreach (var busname in dbus.list_names()) { - if (busname.has_prefix(prefix)) - list.append(busname.replace(prefix, "")); - } - } catch (Error err) { - critical(err.message); - } - - return list; - } - - public static void quit_instance(string instance) { - try { - IApplication proxy = Bus.get_proxy_sync( - BusType.SESSION, - "io.Astal." + instance, - "/io/Astal/Application" - ); - - proxy.quit(); - } catch (Error err) { - critical(err.message); - } - } - - public static void open_inspector(string instance) { - try { - IApplication proxy = Bus.get_proxy_sync( - BusType.SESSION, - "io.Astal." + instance, - "/io/Astal/Application" - ); - - proxy.inspector(); - } catch (Error err) { - critical(err.message); - } - } - - public static void toggle_window_by_name(string instance, string window) { - try { - IApplication proxy = Bus.get_proxy_sync( - BusType.SESSION, - "io.Astal." + instance, - "/io/Astal/Application" - ); - - proxy.toggle_window(window); - } catch (Error err) { - critical(err.message); - } - } - - public static string send_message(string instance_name, string msg) { - var rundir = GLib.Environment.get_user_runtime_dir(); - var socket_path = @"$rundir/$instance_name.sock"; - var client = new SocketClient(); - - try { - var conn = client.connect(new UnixSocketAddress(socket_path), null); - conn.output_stream.write(msg.concat("\x04").data); - - var stream = new DataInputStream(conn.input_stream); - return stream.read_upto("\x04", -1, null, null); - } catch (Error err) { - printerr(err.message); - return ""; - } - } -} - -[DBus (name="org.freedesktop.DBus")] -private interface DBusImpl : DBusProxy { - public abstract string[] list_names() throws GLib.Error; -} - -[DBus (name="io.Astal.Application")] -private interface IApplication : DBusProxy { - public abstract void quit() throws GLib.Error; - public abstract void inspector() throws GLib.Error; - public abstract void toggle_window(string window) throws GLib.Error; - public abstract string message(string window) throws GLib.Error; -} - -public async string read_sock(SocketConnection conn) { - try { - var stream = new DataInputStream(conn.input_stream); - return yield stream.read_upto_async("\x04", -1, Priority.DEFAULT, null, null); - } catch (Error err) { - critical(err.message); - return err.message; - } -} - -public async void write_sock(SocketConnection conn, string response) { - try { - yield conn.output_stream.write_async( - response.concat("\x04").data, - Priority.DEFAULT); - } catch (Error err) { - critical(err.message); - } -} -} diff --git a/core/src/cli.vala b/core/src/cli.vala deleted file mode 100644 index 0b60cd1..0000000 --- a/core/src/cli.vala +++ /dev/null @@ -1,87 +0,0 @@ -private static bool version; -private static bool help; -private static bool list; -private static bool quit; -private static bool inspector; -private static string? toggle_window; -private static string? instance_name; - -private const GLib.OptionEntry[] options = { - { "version", 'v', OptionFlags.NONE, OptionArg.NONE, ref version, null, null }, - { "help", 'h', OptionFlags.NONE, OptionArg.NONE, ref help, null, null }, - { "list", 'l', OptionFlags.NONE, OptionArg.NONE, ref list, null, null }, - { "quit", 'q', OptionFlags.NONE, OptionArg.NONE, ref quit, null, null }, - { "quit", 'q', OptionFlags.NONE, OptionArg.NONE, ref quit, null, null }, - { "inspector", 'I', OptionFlags.NONE, OptionArg.NONE, ref inspector, null, null }, - { "toggle-window", 't', OptionFlags.NONE, OptionArg.STRING, ref toggle_window, null, null }, - { "instance", 'i', OptionFlags.NONE, OptionArg.STRING, ref instance_name, null, null }, - { null }, -}; - -int main(string[] argv) { - try { - var opts = new OptionContext(); - opts.add_main_entries(options, null); - opts.set_help_enabled(false); - opts.set_ignore_unknown_options(false); - opts.parse(ref argv); - } catch (OptionError err) { - printerr (err.message); - return 1; - } - - if (help) { - print("Client for Astal.Application instances\n\n"); - print("Usage:\n"); - print(" %s [flags] message\n\n", argv[0]); - print("Flags:\n"); - print(" -h, --help Print this help and exit\n"); - print(" -v, --version Print version number and exit\n"); - print(" -l, --list List running Astal instances and exit\n"); - print(" -q, --quit Quit an Astal.Application instance\n"); - print(" -i, --instance Instance name of the Astal instance\n"); - print(" -I, --inspector Open up Gtk debug tool\n"); - print(" -t, --toggle-window Show or hide a window\n"); - return 0; - } - - if (version) { - print(Astal.VERSION); - return 0; - } - - if (instance_name == null) - instance_name = "astal"; - - if (list) { - foreach (var name in Astal.Application.get_instances()) - stdout.printf("%s\n", name); - - return 0; - } - - if (quit) { - Astal.Application.quit_instance(instance_name); - return 0; - } - - if (inspector) { - Astal.Application.open_inspector(instance_name); - return 0; - } - - if (toggle_window != null) { - Astal.Application.toggle_window_by_name(instance_name, toggle_window); - return 0; - } - - var request = ""; - for (var i = 1; i < argv.length; ++i) { - request = request.concat(" ", argv[i]); - } - - var reply = Astal.Application.send_message(instance_name, request); - print("%s\n", reply); - - return 0; -} diff --git a/core/src/config.vala.in b/core/src/config.vala.in deleted file mode 100644 index 88bfe9c..0000000 --- a/core/src/config.vala.in +++ /dev/null @@ -1,6 +0,0 @@ -namespace Astal { - public const int MAJOR_VERSION = @MAJOR_VERSION@; - public const int MINOR_VERSION = @MINOR_VERSION@; - public const int MICRO_VERSION = @MICRO_VERSION@; - public const string VERSION = "@VERSION@"; -} diff --git a/core/src/file.vala b/core/src/file.vala deleted file mode 100644 index d8acccc..0000000 --- a/core/src/file.vala +++ /dev/null @@ -1,81 +0,0 @@ -namespace Astal { -public string read_file(string path) { - var str = ""; - try { - FileUtils.get_contents(path, out str, null); - } catch (Error error) { - critical(error.message); - } - return str; -} - -public async string read_file_async(string path) throws Error { - uint8[] content; - yield File.new_for_path(path).load_contents_async(null, out content, null); - return (string)content; -} - -public void write_file(string path, string content) { - try { - FileUtils.set_contents(path, content); - } catch (Error error) { - critical(error.message); - } -} - -public async void write_file_async(string path, string content) throws Error { - yield File.new_for_path(path).replace_contents_async( - content.data, - null, - false, - GLib.FileCreateFlags.REPLACE_DESTINATION, - null, - null); -} - -public FileMonitor? monitor_file(string path, Closure callback) { - try { - var file = File.new_for_path(path); - var mon = file.monitor(GLib.FileMonitorFlags.NONE); - - mon.changed.connect((file, _file, event) => { - var f = Value(Type.STRING); - var e = Value(Type.INT); - var ret = Value(Type.POINTER); - - f.set_string(file.get_path()); - e.set_int(event); - - callback.invoke(ref ret, { f, e }); - }); - - if (FileUtils.test(path, FileTest.IS_DIR)) { - var enumerator = file.enumerate_children("standard::*", - FileQueryInfoFlags.NONE, null); - - var i = enumerator.next_file(null); - while (i != null) { - if (i.get_file_type() == FileType.DIRECTORY) { - var filepath = file.get_child(i.get_name()).get_path(); - if (filepath != null) { - var m = monitor_file(path, callback); - mon.notify["cancelled"].connect(() => { - m.cancel(); - }); - } - } - i = enumerator.next_file(null); - } - } - - mon.ref(); - mon.notify["cancelled"].connect(() => { - mon.unref(); - }); - return mon; - } catch (Error error) { - critical(error.message); - return null; - } -} -} diff --git a/core/src/idle-inhibit.c b/core/src/idle-inhibit.c deleted file mode 100644 index 48f2471..0000000 --- a/core/src/idle-inhibit.c +++ /dev/null @@ -1,114 +0,0 @@ -#include "idle-inhibit.h" - -#include <gdk/gdk.h> -#include <gdk/gdkwayland.h> -#include <gio/gio.h> -#include <glib-object.h> -#include <glib.h> -#include <gtk/gtk.h> -#include <wayland-client-protocol.h> -#include <wayland-client.h> - -#include "idle-inhibit-unstable-v1-client.h" - -struct _AstalInhibitManager { - GObject parent_instance; -}; - -typedef struct { - gboolean init; - struct wl_registry* wl_registry; - struct wl_display* display; - struct zwp_idle_inhibit_manager_v1* idle_inhibit_manager; -} AstalInhibitManagerPrivate; - -G_DEFINE_TYPE_WITH_PRIVATE(AstalInhibitManager, astal_inhibit_manager, G_TYPE_OBJECT) - -AstalInhibitor* astal_inhibit_manager_inhibit(AstalInhibitManager* self, GtkWindow* window) { - AstalInhibitManagerPrivate* priv = astal_inhibit_manager_get_instance_private(self); - g_assert_true(priv->init); - GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window)); - struct wl_surface* surface = gdk_wayland_window_get_wl_surface(gdk_window); - return zwp_idle_inhibit_manager_v1_create_inhibitor(priv->idle_inhibit_manager, surface); -} - -static void global_registry_handler(void* data, struct wl_registry* registry, uint32_t id, - const char* interface, uint32_t version) { - AstalInhibitManager* self = ASTAL_INHIBIT_MANAGER(data); - AstalInhibitManagerPrivate* priv = astal_inhibit_manager_get_instance_private(self); - - if (strcmp(interface, zwp_idle_inhibit_manager_v1_interface.name) == 0) { - priv->idle_inhibit_manager = - wl_registry_bind(registry, id, &zwp_idle_inhibit_manager_v1_interface, 1); - } -} - -static void global_registry_remover(void* data, struct wl_registry* registry, uint32_t id) { - // neither inhibit_manager nor inhibitor is going to be removed by the compositor, so we don't - // need do anything here. -} - -static const struct wl_registry_listener registry_listener = {global_registry_handler, - global_registry_remover}; - -static gboolean astal_inhibit_manager_wayland_init(AstalInhibitManager* self) { - AstalInhibitManagerPrivate* priv = astal_inhibit_manager_get_instance_private(self); - - if (priv->init) return TRUE; - - GdkDisplay* gdk_display = gdk_display_get_default(); - priv->display = gdk_wayland_display_get_wl_display(gdk_display); - - priv->wl_registry = wl_display_get_registry(priv->display); - wl_registry_add_listener(priv->wl_registry, ®istry_listener, self); - - wl_display_roundtrip(priv->display); - - if (priv->idle_inhibit_manager == NULL) { - g_critical("Can not connect idle inhibitor protocol"); - return FALSE; - } - - priv->init = TRUE; - return TRUE; -} - -AstalInhibitManager* astal_inhibit_manager_get_default() { - static AstalInhibitManager* self = NULL; - - if (self == NULL) { - self = g_object_new(ASTAL_TYPE_INHIBIT_MANAGER, NULL); - if (!astal_inhibit_manager_wayland_init(self)) { - g_object_unref(self); - self = NULL; - } - } - - return self; -} - -static void astal_inhibit_manager_init(AstalInhibitManager* self) { - AstalInhibitManagerPrivate* priv = astal_inhibit_manager_get_instance_private(self); - priv->init = FALSE; - priv->display = NULL; - priv->wl_registry = NULL; - priv->idle_inhibit_manager = NULL; -} - -static void astal_inhibit_manager_finalize(GObject* object) { - AstalInhibitManager* self = ASTAL_INHIBIT_MANAGER(object); - AstalInhibitManagerPrivate* priv = astal_inhibit_manager_get_instance_private(self); - - if (priv->display != NULL) wl_display_roundtrip(priv->display); - - if (priv->wl_registry != NULL) wl_registry_destroy(priv->wl_registry); - if (priv->idle_inhibit_manager != NULL) - zwp_idle_inhibit_manager_v1_destroy(priv->idle_inhibit_manager); - - G_OBJECT_CLASS(astal_inhibit_manager_parent_class)->finalize(object); -} - -static void astal_inhibit_manager_class_init(AstalInhibitManagerClass* class) { - GObjectClass* object_class = G_OBJECT_CLASS(class); - object_class->finalize = astal_inhibit_manager_finalize; -} diff --git a/core/src/idle-inhibit.h b/core/src/idle-inhibit.h deleted file mode 100644 index 5e9a3ab..0000000 --- a/core/src/idle-inhibit.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef ASTAL_IDLE_INHIBITOR_H -#define ASTAL_IDLE_INHIBITOR_H - -#include <glib-object.h> -#include <gtk/gtk.h> - -#include "idle-inhibit-unstable-v1-client.h" - -G_BEGIN_DECLS - -#define ASTAL_TYPE_INHIBIT_MANAGER (astal_inhibit_manager_get_type()) - -G_DECLARE_FINAL_TYPE(AstalInhibitManager, astal_inhibit_manager, ASTAL, INHIBIT_MANAGER, GObject) - -typedef struct zwp_idle_inhibitor_v1 AstalInhibitor; - -AstalInhibitManager* astal_inhibit_manager_get_default(); -AstalInhibitor* astal_inhibit_manager_inhibit(AstalInhibitManager* self, GtkWindow* window); - -G_END_DECLS - -#endif // !ASTAL_IDLE_INHIBITOR_H diff --git a/core/src/meson.build b/core/src/meson.build deleted file mode 100644 index b5adda2..0000000 --- a/core/src/meson.build +++ /dev/null @@ -1,136 +0,0 @@ -version_split = meson.project_version().split('.') -api_version = version_split[0] + '.' + version_split[1] -gir = 'Astal-' + api_version + '.gir' -typelib = 'Astal-' + api_version + '.typelib' - -vapi_dir = meson.current_source_dir() / 'vapi' -add_project_arguments(['--vapidir', vapi_dir], language: 'vala') - -config = configure_file( - input: 'config.vala.in', - output: 'config.vala', - configuration: { - 'VERSION': meson.project_version(), - 'MAJOR_VERSION': version_split[0], - 'MINOR_VERSION': version_split[1], - 'MICRO_VERSION': version_split[2], - }, -) - -pkgconfig_deps = [ - dependency('glib-2.0'), - dependency('gio-unix-2.0'), - dependency('gobject-2.0'), - dependency('gio-2.0'), - dependency('gtk+-3.0'), - dependency('gdk-pixbuf-2.0'), - dependency('gtk-layer-shell-0'), - dependency('wayland-client'), -] - -deps = pkgconfig_deps + meson.get_compiler('c').find_library('m') - - -wayland_protos = dependency('wayland-protocols') -wayland_scanner = find_program('wayland-scanner') - -wl_protocol_dir = wayland_protos.get_variable(pkgconfig: 'pkgdatadir') - -gen_client_header = generator( - wayland_scanner, - output: ['@[email protected]'], - arguments: ['-c', 'client-header', '@INPUT@', '@BUILD_DIR@/@[email protected]'], -) - -gen_private_code = generator( - wayland_scanner, - output: ['@[email protected]'], - arguments: ['-c', 'private-code', '@INPUT@', '@BUILD_DIR@/@[email protected]'], -) - -protocols = [ - join_paths(wl_protocol_dir, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml') -] - -client_protocol_srcs = [] - -foreach protocol : protocols - client_header = gen_client_header.process(protocol) - code = gen_private_code.process(protocol) - client_protocol_srcs += [client_header, code] -endforeach - -sources = [ - config, - 'widget/box.vala', - 'widget/button.vala', - 'widget/centerbox.vala', - 'widget/circularprogress.vala', - 'widget/eventbox.vala', - 'widget/icon.vala', - 'widget/label.vala', - 'widget/levelbar.vala', - 'widget/overlay.vala', - 'widget/scrollable.vala', - 'widget/slider.vala', - 'widget/stack.vala', - 'widget/widget.vala', - 'widget/window.vala', - 'astal.vala', - 'file.vala', - 'process.vala', - 'time.vala', - 'variable.vala', - 'idle-inhibit.h', - 'idle-inhibit.c', -] + client_protocol_srcs - -if get_option('lib') - lib = library( - meson.project_name(), - sources, - dependencies: deps, - vala_args: ['--pkg', 'AstalInhibitManager'], - vala_header: meson.project_name() + '.h', - vala_vapi: meson.project_name() + '-' + api_version + '.vapi', - vala_gir: gir, - version: meson.project_version(), - install: true, - install_dir: [true, true, true, true], - ) - - import('pkgconfig').generate( - lib, - name: meson.project_name(), - filebase: meson.project_name() + '-' + api_version, - version: meson.project_version(), - subdirs: meson.project_name(), - requires: pkgconfig_deps, - install_dir: libdir / 'pkgconfig', - ) - - custom_target( - typelib, - command: [ - find_program('g-ir-compiler'), - '--output', '@OUTPUT@', - '--shared-library', libdir / '@PLAINNAME@', - meson.current_build_dir() / gir, - ], - input: lib, - output: typelib, - depends: lib, - install: true, - install_dir: libdir / 'girepository-1.0', - ) -endif - -if get_option('cli') - executable( - meson.project_name(), - ['cli.vala', sources], - vala_args: ['--pkg', 'AstalInhibitManager'], - dependencies: deps, - install: true, - ) -endif diff --git a/core/src/process.vala b/core/src/process.vala deleted file mode 100644 index 073fe93..0000000 --- a/core/src/process.vala +++ /dev/null @@ -1,119 +0,0 @@ -public class Astal.Process : Object { - private void read_stream(DataInputStream stream, bool err) { - stream.read_line_utf8_async.begin(Priority.DEFAULT, null, (_, res) => { - try { - var output = stream.read_line_utf8_async.end(res); - if (output != null) { - if (err) - stdout(output.strip()); - else - stderr(output.strip()); - - read_stream(stream, err); - } - } catch (Error err) { - printerr("%s\n", err.message); - } - }); - } - - private DataInputStream out_stream; - private DataInputStream err_stream; - private DataOutputStream in_stream; - private Subprocess process; - public string[] argv { construct; get; } - - public signal void stdout (string out); - public signal void stderr (string err); - - public void kill() { - process.force_exit(); - } - - public void signal(int signal_num) { - process.send_signal(signal_num); - } - - public void write(string in) throws Error { - in_stream.put_string(in); - } - - public void write_async(string in) { - in_stream.write_all_async.begin( - in.data, - Priority.DEFAULT, null, (_, res) => { - try { - in_stream.write_all_async.end(res, null); - } catch (Error err) { - printerr("%s\n", err.message); - } - } - ); - } - - public Process.subprocessv(string[] cmd) throws Error { - Object(argv: cmd); - process = new Subprocess.newv(cmd, - SubprocessFlags.STDIN_PIPE | - SubprocessFlags.STDERR_PIPE | - SubprocessFlags.STDOUT_PIPE - ); - out_stream = new DataInputStream(process.get_stdout_pipe()); - err_stream = new DataInputStream(process.get_stderr_pipe()); - in_stream = new DataOutputStream(process.get_stdin_pipe()); - read_stream(out_stream, true); - read_stream(err_stream, false); - } - - public static Process subprocess(string cmd) throws Error { - string[] argv; - Shell.parse_argv(cmd, out argv); - return new Process.subprocessv(argv); - } - - public static string execv(string[] cmd) throws Error { - var process = new Subprocess.newv( - cmd, - SubprocessFlags.STDERR_PIPE | - SubprocessFlags.STDOUT_PIPE - ); - - string err_str, out_str; - process.communicate_utf8(null, null, out out_str, out err_str); - var success = process.get_successful(); - process.dispose(); - if (success) - return out_str.strip(); - else - throw new IOError.FAILED(err_str.strip()); - } - - public static string exec(string cmd) throws Error { - string[] argv; - Shell.parse_argv(cmd, out argv); - return Process.execv(argv); - } - - public static async string exec_asyncv(string[] cmd) throws Error { - var process = new Subprocess.newv( - cmd, - SubprocessFlags.STDERR_PIPE | - SubprocessFlags.STDOUT_PIPE - ); - - string err_str, out_str; - yield process.communicate_utf8_async(null, null, out out_str, out err_str); - var success = process.get_successful(); - process.dispose(); - if (success) - return out_str.strip(); - else - throw new IOError.FAILED(err_str.strip()); - } - - public static async string exec_async(string cmd) throws Error { - string[] argv; - Shell.parse_argv(cmd, out argv); - return yield exec_asyncv(argv); - } -} diff --git a/core/src/time.vala b/core/src/time.vala deleted file mode 100644 index 4034c04..0000000 --- a/core/src/time.vala +++ /dev/null @@ -1,73 +0,0 @@ -namespace Astal { -public class Time : Object { - public signal void now (); - public signal void cancelled (); - private Cancellable cancellable; - private uint timeout_id; - private bool fulfilled = false; - - construct { - cancellable = new Cancellable(); - cancellable.cancelled.connect(() => { - if (!fulfilled) { - Source.remove(timeout_id); - cancelled(); - dispose(); - } - }); - } - - private void connect_closure(Closure? closure) { - if (closure == null) - return; - - now.connect(() => { - Value ret = Value(Type.POINTER); // void - closure.invoke(ref ret, {}); - }); - } - - public Time.interval_prio(uint interval, int prio = Priority.DEFAULT, Closure? fn) { - connect_closure(fn); - Idle.add_once(() => now()); - timeout_id = Timeout.add(interval, () => { - now(); - return Source.CONTINUE; - }, prio); - } - - public Time.timeout_prio(uint timeout, int prio = Priority.DEFAULT, Closure? fn) { - connect_closure(fn); - timeout_id = Timeout.add(timeout, () => { - now(); - fulfilled = true; - return Source.REMOVE; - }, prio); - } - - public Time.idle_prio(int prio = Priority.DEFAULT_IDLE, Closure? fn) { - connect_closure(fn); - timeout_id = Idle.add(() => { - now(); - fulfilled = true; - return Source.REMOVE; - }, prio); - } - - public static Time interval(uint interval, Closure? fn) { - return new Time.interval_prio(interval, Priority.DEFAULT, fn); - } - - public static Time timeout(uint timeout, Closure? fn) { - return new Time.timeout_prio(timeout, Priority.DEFAULT, fn); - } - - public static Time idle(Closure? fn) { - return new Time.idle_prio(Priority.DEFAULT_IDLE, fn); - } - - public void cancel() { - cancellable.cancel(); - } -} -} diff --git a/core/src/vapi/AstalInhibitManager.vapi b/core/src/vapi/AstalInhibitManager.vapi deleted file mode 100644 index 6232a3c..0000000 --- a/core/src/vapi/AstalInhibitManager.vapi +++ /dev/null @@ -1,13 +0,0 @@ -[CCode (cprefix = "Astal", gir_namespace = "Astal", lower_case_cprefix = "astal_")] -namespace Astal { - [CCode (cheader_filename = "idle-inhibit.h", type_id = "astal_idle_inhibit_manager_get_type()")] - public class InhibitManager : GLib.Object { - public static unowned InhibitManager? get_default(); - public Inhibitor inhibit (Gtk.Window window); - } - - [CCode (cheader_filename = "idle-inhibit.h", free_function = "zwp_idle_inhibitor_v1_destroy")] - [Compact] - public class Inhibitor { - } -} diff --git a/core/src/variable.vala b/core/src/variable.vala deleted file mode 100644 index c7edb16..0000000 --- a/core/src/variable.vala +++ /dev/null @@ -1,196 +0,0 @@ -namespace Astal { -public class VariableBase : Object { - public signal void changed (); - public signal void dropped (); - public signal void error (string err); - - // lua-lgi crashes when using its emitting mechanism - public void emit_changed() { changed(); } - public void emit_dropped() { dropped(); } - public void emit_error(string err) { this.error(err); } - - ~VariableBase() { - dropped(); - } -} - -public class Variable : VariableBase { - public Value value { owned get; set; } - - private uint poll_id = 0; - private Process? watch_proc; - - private uint poll_interval { get; set; default = 1000; } - private string[] poll_exec { get; set; } - private Closure? poll_transform { get; set; } - private Closure? poll_fn { get; set; } - - private Closure? watch_transform { get; set; } - private string[] watch_exec { get; set; } - - public Variable(Value init) { - Object(value: init); - } - - public Variable poll( - uint interval, - string exec, - Closure? transform - ) throws Error { - string[] argv; - Shell.parse_argv(exec, out argv); - return pollv(interval, argv, transform); - } - - public Variable pollv( - uint interval, - string[] execv, - Closure? transform - ) throws Error { - if (is_polling()) - stop_poll(); - - poll_interval = interval; - poll_exec = execv; - poll_transform = transform; - poll_fn = null; - start_poll(); - return this; - } - - public Variable pollfn( - uint interval, - Closure fn - ) throws Error { - if (is_polling()) - stop_poll(); - - poll_interval = interval; - poll_fn = fn; - poll_exec = null; - start_poll(); - return this; - } - - public Variable watch( - string exec, - Closure? transform - ) throws Error { - string[] argv; - Shell.parse_argv(exec, out argv); - return watchv(argv, transform); - } - - public Variable watchv( - string[] execv, - Closure? transform - ) throws Error { - if (is_watching()) - stop_watch(); - - watch_exec = execv; - watch_transform = transform; - start_watch(); - return this; - } - - construct { - notify["value"].connect(() => changed()); - dropped.connect(() => { - if (is_polling()) - stop_poll(); - - if (is_watching()) - stop_watch(); - }); - } - - private void set_closure(string val, Closure? transform) { - if (transform != null) { - var str = Value(typeof(string)); - str.set_string(val); - - var ret_val = Value(this.value.type()); - transform.invoke(ref ret_val, { str, this.value }); - this.value = ret_val; - } - else { - if (this.value.type() == Type.STRING && this.value.get_string() == val) - return; - - var str = Value(typeof(string)); - str.set_string(val); - this.value = str; - } - } - - private void set_fn() { - var ret_val = Value(this.value.type()); - poll_fn.invoke(ref ret_val, { this.value }); - this.value = ret_val; - } - - public void start_poll() throws Error { - return_if_fail(poll_id == 0); - - if (poll_fn != null) { - set_fn(); - poll_id = Timeout.add(poll_interval, () => { - set_fn(); - return Source.CONTINUE; - }, Priority.DEFAULT); - } - if (poll_exec != null) { - Process.exec_asyncv.begin(poll_exec, (_, res) => { - try { - var str = Process.exec_asyncv.end(res); - set_closure(str, poll_transform); - } catch (Error err) { - this.error(err.message); - } - }); - poll_id = Timeout.add(poll_interval, () => { - Process.exec_asyncv.begin(poll_exec, (_, res) => { - try { - var str = Process.exec_asyncv.end(res); - set_closure(str, poll_transform); - } catch (Error err) { - this.error(err.message); - Source.remove(poll_id); - poll_id = 0; - } - }); - return Source.CONTINUE; - }, Priority.DEFAULT); - } - } - - public void start_watch() throws Error { - return_if_fail(watch_proc == null); - return_if_fail(watch_exec != null); - - watch_proc = new Process.subprocessv(watch_exec); - watch_proc.stdout.connect((str) => set_closure(str, watch_transform)); - watch_proc.stderr.connect((str) => this.error(str)); - } - - public void stop_poll() { - return_if_fail(poll_id != 0); - Source.remove(poll_id); - poll_id = 0; - } - - public void stop_watch() { - return_if_fail(watch_proc != null); - watch_proc.kill(); - watch_proc = null; - } - - public bool is_polling() { return poll_id > 0; } - public bool is_watching() { return watch_proc != null; } - - ~Variable() { - dropped(); - } -} -} diff --git a/core/src/widget/box.vala b/core/src/widget/box.vala deleted file mode 100644 index 943c821..0000000 --- a/core/src/widget/box.vala +++ /dev/null @@ -1,62 +0,0 @@ -namespace Astal { -public class Box : Gtk.Box { - [CCode (notify = false)] - public bool vertical { - get { return orientation == Gtk.Orientation.VERTICAL; } - set { orientation = value ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL; } - } - - public List<weak Gtk.Widget> children { - set { _set_children(value); } - owned get { return get_children(); } - } - - public new Gtk.Widget child { - owned get { return _get_child(); } - set { _set_child(value); } - } - - construct { - notify["orientation"].connect(() => { - notify_property("vertical"); - }); - } - - private void _set_child(Gtk.Widget child) { - var list = new List<weak Gtk.Widget>(); - list.append(child); - _set_children(list); - } - - private Gtk.Widget? _get_child() { - foreach(var child in get_children()) - return child; - - return null; - } - - private void _set_children(List<weak Gtk.Widget> arr) { - foreach(var child in get_children()) { - remove(child); - } - - foreach(var child in arr) - add(child); - } - - public Box(bool vertical, List<weak Gtk.Widget> children) { - this.vertical = vertical; - _set_children(children); - } - - public Box.newh(List<weak Gtk.Widget> children) { - this.vertical = false; - _set_children(children); - } - - public Box.newv(List<weak Gtk.Widget> children) { - this.vertical = true; - _set_children(children); - } -} -} diff --git a/core/src/widget/button.vala b/core/src/widget/button.vala deleted file mode 100644 index ad60da1..0000000 --- a/core/src/widget/button.vala +++ /dev/null @@ -1,101 +0,0 @@ -namespace Astal { -public class Button : Gtk.Button { - public signal void hover (HoverEvent event); - public signal void hover_lost (HoverEvent event); - public signal void click (ClickEvent event); - public signal void click_release (ClickEvent event); - public signal void scroll (ScrollEvent event); - - construct { - add_events(Gdk.EventMask.SCROLL_MASK); - add_events(Gdk.EventMask.SMOOTH_SCROLL_MASK); - - enter_notify_event.connect((self, event) => { - hover(HoverEvent(event) { lost = false }); - }); - - leave_notify_event.connect((self, event) => { - hover_lost(HoverEvent(event) { lost = true }); - }); - - button_press_event.connect((event) => { - click(ClickEvent(event) { release = false }); - }); - - button_release_event.connect((event) => { - click_release(ClickEvent(event) { release = true }); - }); - - scroll_event.connect((event) => { - scroll(ScrollEvent(event)); - }); - } -} - -public enum MouseButton { - PRIMARY = 1, - MIDDLE = 2, - SECONDARY = 3, - BACK = 4, - FORWARD = 5, -} - -// these structs are here because gjs converts every event -// into a union Gdk.Event, which cannot be destructured -// and are not as convinent to work with as a struct -public struct ClickEvent { - bool release; - uint time; - double x; - double y; - Gdk.ModifierType modifier; - MouseButton button; - - public ClickEvent(Gdk.EventButton event) { - this.time = event.time; - this.x = event.x; - this.y = event.y; - this.button = (MouseButton)event.button; - this.modifier = event.state; - } -} - -public struct HoverEvent { - bool lost; - uint time; - double x; - double y; - Gdk.ModifierType modifier; - Gdk.CrossingMode mode; - Gdk.NotifyType detail; - - public HoverEvent(Gdk.EventCrossing event) { - this.time = event.time; - this.x = event.x; - this.y = event.y; - this.modifier = event.state; - this.mode = event.mode; - this.detail = event.detail; - } -} - -public struct ScrollEvent { - uint time; - double x; - double y; - Gdk.ModifierType modifier; - Gdk.ScrollDirection direction; - double delta_x; - double delta_y; - - public ScrollEvent(Gdk.EventScroll event) { - this.time = event.time; - this.x = event.x; - this.y = event.y; - this.modifier = event.state; - this.direction = event.direction; - this.delta_x = event.delta_x; - this.delta_y = event.delta_y; - } -} -} diff --git a/core/src/widget/centerbox.vala b/core/src/widget/centerbox.vala deleted file mode 100644 index 0588828..0000000 --- a/core/src/widget/centerbox.vala +++ /dev/null @@ -1,54 +0,0 @@ -namespace Astal { -public class CenterBox : Gtk.Box { - [CCode (notify = false)] - public bool vertical { - get { return orientation == Gtk.Orientation.VERTICAL; } - set { orientation = value ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL; } - } - - construct { - notify["orientation"].connect(() => { - notify_property("vertical"); - }); - } - - static construct { - set_css_name("centerbox"); - } - - private Gtk.Widget _start_widget; - public Gtk.Widget start_widget { - get { return _start_widget; } - set { - if (_start_widget != null) - remove(_start_widget); - - if (value != null) - pack_start(value, true, true, 0); - } - } - - private Gtk.Widget _end_widget; - public Gtk.Widget end_widget { - get { return _end_widget; } - set { - if (_end_widget != null) - remove(_end_widget); - - if (value != null) - pack_end(value, true, true, 0); - } - } - - public Gtk.Widget center_widget { - get { return get_center_widget(); } - set { - if (center_widget != null) - remove(center_widget); - - if (value != null) - set_center_widget(value); - } - } -} -} diff --git a/core/src/widget/circularprogress.vala b/core/src/widget/circularprogress.vala deleted file mode 100644 index 4e1410d..0000000 --- a/core/src/widget/circularprogress.vala +++ /dev/null @@ -1,182 +0,0 @@ -namespace Astal { -public class CircularProgress : Gtk.Bin { - public double start_at { get; set; } - public double end_at { get; set; } - public double value { get; set; } - public bool inverted { get; set; } - public bool rounded { get; set; } - - construct { - notify["start-at"].connect(queue_draw); - notify["end-at"].connect(queue_draw); - notify["value"].connect(queue_draw); - notify["inverted"].connect(queue_draw); - notify["rounded"].connect(queue_draw); - notify["child"].connect(queue_draw); - } - - static construct { - set_css_name("circular-progress"); - } - - public override void get_preferred_height(out int minh, out int nath) { - var val = get_style_context().get_property("min-height", Gtk.StateFlags.NORMAL); - if (val.get_int() <= 0) { - minh = 40; - nath = 40; - } - - minh = val.get_int(); - nath = val.get_int(); - } - - public override void get_preferred_width(out int minw, out int natw) { - var val = get_style_context().get_property("min-width", Gtk.StateFlags.NORMAL); - if (val.get_int() <= 0) { - minw = 40; - natw = 40; - } - - minw = val.get_int(); - natw = val.get_int(); - } - - private double to_radian(double percentage) { - percentage = Math.floor(percentage * 100); - return (percentage / 100) * (2 * Math.PI); - } - - private bool is_full_circle(double start, double end, double epsilon = 1e-10) { - // Ensure that start and end are between 0 and 1 - start = (start % 1 + 1) % 1; - end = (end % 1 + 1) % 1; - - // Check if the difference between start and end is close to 1 - return Math.fabs(start - end) <= epsilon; - } - - private double scale_arc_value(double start, double end, double value) { - // Ensure that start and end are between 0 and 1 - start = (start % 1 + 1) % 1; - end = (end % 1 + 1) % 1; - - // Calculate the length of the arc - var arc_length = end - start; - if (arc_length < 0) - arc_length += 1; // Adjust for circular representation - - // Calculate the position on the arc based on the percentage value - var scaled = arc_length + value; - - // Ensure the position is between 0 and 1 - return (scaled % 1 + 1) % 1; - } - - private double min(double[] arr) { - double min = arr[0]; - foreach(var i in arr) - if (min > i) min = i; - return min; - } - - private double max(double[] arr) { - double max = arr[0]; - foreach(var i in arr) - if (max < i) max = i; - return max; - } - - public override bool draw(Cairo.Context cr) { - Gtk.Allocation allocation; - get_allocation(out allocation); - - var styles = get_style_context(); - var width = allocation.width; - var height = allocation.height; - var thickness = styles.get_property("font-size", Gtk.StateFlags.NORMAL).get_double(); - var margin = styles.get_margin(Gtk.StateFlags.NORMAL); - var fg = styles.get_color(Gtk.StateFlags.NORMAL); - var bg = styles.get_background_color(Gtk.StateFlags.NORMAL); - - var bg_stroke = thickness + min({margin.bottom, margin.top, margin.left, margin.right}); - var fg_stroke = thickness; - var radius = min({width, height}) / 2.0 - max({bg_stroke, fg_stroke}) / 2.0; - var center_x = width / 2; - var center_y = height / 2; - - var start_background = to_radian(start_at); - var end_background = to_radian(end_at); - var ranged_value = value + start_at; - - var is_circle = is_full_circle(this.start_at, this.end_at); - - if (is_circle) { - // Redefine end_draw in radius to create an accurate full circle - end_background = start_background + 2 * Math.PI; - ranged_value = to_radian(value); - } else { - // Range the value for the arc shape - ranged_value = to_radian(scale_arc_value( - start_at, - end_at, - value - )); - } - - double start_progress, end_progress; - - if (inverted) { - start_progress = end_background - ranged_value; - end_progress = end_background; - } else { - start_progress = start_background; - end_progress = start_background + ranged_value; - } - - // Draw background - cr.set_source_rgba(bg.red, bg.green, bg.blue, bg.alpha); - cr.arc(center_x, center_y, radius, start_background, end_background); - cr.set_line_width(bg_stroke); - cr.stroke(); - - // Draw rounded background ends - if (rounded) { - var start_x = center_x + Math.cos(start_background) * radius; - var start_y = center_y + Math.sin(start_background) * radius; - var end_x = center_x + Math.cos(end_background) * radius; - var end_y = center_y + Math.sin(end_background) * radius; - cr.set_line_width(0); - cr.arc(start_x, start_y, bg_stroke / 2, 0, 0 - 0.01); - cr.fill(); - cr.arc(end_x, end_y, bg_stroke / 2, 0, 0 - 0.01); - cr.fill(); - } - - // Draw progress - cr.set_source_rgba(fg.red, fg.green, fg.blue, fg.alpha); - cr.arc(center_x, center_y, radius, start_progress, end_progress); - cr.set_line_width(fg_stroke); - cr.stroke(); - - // Draw rounded progress ends - if (rounded) { - var start_x = center_x + Math.cos(start_progress) * radius; - var start_y = center_y + Math.sin(start_progress) * radius; - var end_x = center_x + Math.cos(end_progress) * radius; - var end_y = center_y + Math.sin(end_progress) * radius; - cr.set_line_width(0); - cr.arc(start_x, start_y, fg_stroke / 2, 0, 0 - 0.01); - cr.fill(); - cr.arc(end_x, end_y, fg_stroke / 2, 0, 0 - 0.01); - cr.fill(); - } - - if (get_child() != null) { - get_child().size_allocate(allocation); - propagate_draw(get_child(), cr); - } - - return true; - } -} -} diff --git a/core/src/widget/eventbox.vala b/core/src/widget/eventbox.vala deleted file mode 100644 index 6b715cc..0000000 --- a/core/src/widget/eventbox.vala +++ /dev/null @@ -1,66 +0,0 @@ -namespace Astal { -public class EventBox : Gtk.EventBox { - public signal void hover (HoverEvent event); - public signal void hover_lost (HoverEvent event); - public signal void click (ClickEvent event); - public signal void click_release (ClickEvent event); - public signal void scroll (ScrollEvent event); - public signal void motion (MotionEvent event); - - static construct { - set_css_name("eventbox"); - } - - construct { - add_events(Gdk.EventMask.SCROLL_MASK); - add_events(Gdk.EventMask.SMOOTH_SCROLL_MASK); - add_events(Gdk.EventMask.POINTER_MOTION_MASK); - - enter_notify_event.connect((self, event) => { - if (event.window == self.get_window() && - event.detail != Gdk.NotifyType.INFERIOR) { - this.set_state_flags(Gtk.StateFlags.PRELIGHT, false); - hover(HoverEvent(event) { lost = false }); - } - }); - - leave_notify_event.connect((self, event) => { - if (event.window == self.get_window() && - event.detail != Gdk.NotifyType.INFERIOR) { - this.unset_state_flags(Gtk.StateFlags.PRELIGHT); - hover_lost(HoverEvent(event) { lost = true }); - } - }); - - button_press_event.connect((event) => { - click(ClickEvent(event) { release = false }); - }); - - button_release_event.connect((event) => { - click_release(ClickEvent(event) { release = true }); - }); - - scroll_event.connect((event) => { - scroll(ScrollEvent(event)); - }); - - motion_notify_event.connect((event) => { - motion(MotionEvent(event)); - }); - } -} - -public struct MotionEvent { - uint time; - double x; - double y; - Gdk.ModifierType modifier; - - public MotionEvent(Gdk.EventMotion event) { - this.time = event.time; - this.x = event.x; - this.y = event.y; - this.modifier = event.state; - } -} -} diff --git a/core/src/widget/icon.vala b/core/src/widget/icon.vala deleted file mode 100644 index 4f1c7f1..0000000 --- a/core/src/widget/icon.vala +++ /dev/null @@ -1,107 +0,0 @@ -namespace Astal { -public Gtk.IconInfo? lookup_icon(string icon) { - var theme = Gtk.IconTheme.get_default(); - return theme.lookup_icon(icon, 16, Gtk.IconLookupFlags.USE_BUILTIN); -} - -public class Icon : Gtk.Image { - private IconType type = IconType.NAMED; - private double size { get; set; default = 14; } - - public new Gdk.Pixbuf pixbuf { get; set; } - public string icon { get; set; default = ""; } - public GLib.Icon g_icon {get; set;} - - private async void display_icon() { - switch(type) { - case IconType.NAMED: - icon_name = icon; - pixel_size = (int)size; - break; - case IconType.FILE: - try { - var file = File.new_for_path(icon); - var stream = yield file.read_async(); - var pb = yield new Gdk.Pixbuf.from_stream_at_scale_async( - stream, - (int)size * scale_factor, - (int)size * scale_factor, - true, - null - ); - var cs = Gdk.cairo_surface_create_from_pixbuf(pb, 0, this.get_window()); - set_from_surface(cs); - } catch (Error err) { - printerr(err.message); - } - break; - case IconType.PIXBUF: - var pb_scaled = pixbuf.scale_simple( - (int)size * scale_factor, - (int)size * scale_factor, - Gdk.InterpType.BILINEAR - ); - if (pb_scaled != null) { - var cs = Gdk.cairo_surface_create_from_pixbuf(pb_scaled, 0, this.get_window()); - set_from_surface(cs); - } - break; - case IconType.GICON: - pixel_size = (int)size; - gicon = g_icon; - break; - - } - } - - static construct { - set_css_name("icon"); - } - - construct { - notify["icon"].connect(() => { - if(FileUtils.test(icon, GLib.FileTest.EXISTS)) - type = IconType.FILE; - else if (lookup_icon(icon) != null) - type = IconType.NAMED; - else { - type = IconType.NAMED; - warning("cannot assign %s as icon, "+ - "it is not a file nor a named icon", icon); - } - display_icon.begin(); - }); - - notify["pixbuf"].connect(() => { - type = IconType.PIXBUF; - display_icon.begin(); - }); - - notify["g-icon"].connect(() => { - type = IconType.GICON; - display_icon.begin(); - }); - - size_allocate.connect(() => { - size = get_style_context() - .get_property("font-size", Gtk.StateFlags.NORMAL).get_double(); - - display_icon.begin(); - }); - - get_style_context().changed.connect(() => { - size = get_style_context() - .get_property("font-size", Gtk.StateFlags.NORMAL).get_double(); - - display_icon.begin(); - }); - } -} - -private enum IconType { - NAMED, - FILE, - PIXBUF, - GICON, -} -} diff --git a/core/src/widget/label.vala b/core/src/widget/label.vala deleted file mode 100644 index 4063b6f..0000000 --- a/core/src/widget/label.vala +++ /dev/null @@ -1,18 +0,0 @@ -using Pango; - -public class Astal.Label : Gtk.Label { - public bool truncate { - set { ellipsize = value ? EllipsizeMode.END : EllipsizeMode.NONE; } - get { return ellipsize == EllipsizeMode.END; } - } - - public new bool justify_fill { - set { justify = value ? Gtk.Justification.FILL : Gtk.Justification.LEFT; } - get { return justify == Gtk.Justification.FILL; } - } - - construct { - notify["ellipsize"].connect(() => notify_property("truncate")); - notify["justify"].connect(() => notify_property("justify_fill")); - } -} diff --git a/core/src/widget/levelbar.vala b/core/src/widget/levelbar.vala deleted file mode 100644 index 1db2cc7..0000000 --- a/core/src/widget/levelbar.vala +++ /dev/null @@ -1,15 +0,0 @@ -namespace Astal { -public class LevelBar : Gtk.LevelBar { - [CCode (notify = false)] - public bool vertical { - get { return orientation == Gtk.Orientation.VERTICAL; } - set { orientation = value ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL; } - } - - construct { - notify["orientation"].connect(() => { - notify_property("vertical"); - }); - } -} -} diff --git a/core/src/widget/overlay.vala b/core/src/widget/overlay.vala deleted file mode 100644 index 207aaa7..0000000 --- a/core/src/widget/overlay.vala +++ /dev/null @@ -1,59 +0,0 @@ -namespace Astal { -public class Overlay : Gtk.Overlay { - public bool pass_through { get; set; } - - public Gtk.Widget? overlay { - get { return overlays.nth_data(0); } - set { - foreach (var ch in get_children()) { - if (ch != child) - remove(ch); - } - - if (value != null) - add_overlay(value); - } - } - - public List<weak Gtk.Widget> overlays { - owned get { return get_children(); } - set { - foreach (var ch in get_children()) { - if (ch != child) - remove(ch); - } - - foreach (var ch in value) - add_overlay(ch); - } - } - - public new Gtk.Widget? child { - get { return get_child(); } - set { - var ch = get_child(); - if (ch != null) - remove(ch); - - if (value != null) - add(value); - } - } - - construct { - notify["pass-through"].connect(() => { - update_pass_through(); - }); - } - - private void update_pass_through() { - foreach (var child in get_children()) - set_overlay_pass_through(child, pass_through); - } - - public new void add_overlay(Gtk.Widget widget) { - base.add_overlay(widget); - set_overlay_pass_through(widget, pass_through); - } -} -} diff --git a/core/src/widget/scrollable.vala b/core/src/widget/scrollable.vala deleted file mode 100644 index 1a0e081..0000000 --- a/core/src/widget/scrollable.vala +++ /dev/null @@ -1,42 +0,0 @@ -namespace Astal { -public class Scrollable : Gtk.ScrolledWindow { - private Gtk.PolicyType _hscroll = Gtk.PolicyType.AUTOMATIC; - private Gtk.PolicyType _vscroll = Gtk.PolicyType.AUTOMATIC; - - public Gtk.PolicyType hscroll { - get { return _hscroll; } - set { - _hscroll = value; - set_policy(value, vscroll); - } - } - - public Gtk.PolicyType vscroll { - get { return _vscroll; } - set { - _vscroll = value; - set_policy(hscroll, value); - } - } - - static construct { - set_css_name("scrollable"); - } - - construct { - if (hadjustment != null) - hadjustment = new Gtk.Adjustment(0,0,0,0,0,0); - - if (vadjustment != null) - vadjustment = new Gtk.Adjustment(0,0,0,0,0,0); - } - - public new Gtk.Widget get_child() { - var ch = base.get_child(); - if (ch is Gtk.Viewport) { - return ch.get_child(); - } - return ch; - } -} -} diff --git a/core/src/widget/slider.vala b/core/src/widget/slider.vala deleted file mode 100644 index 16e6bd2..0000000 --- a/core/src/widget/slider.vala +++ /dev/null @@ -1,73 +0,0 @@ -namespace Astal { -public class Slider : Gtk.Scale { - [CCode (notify = false)] - public bool vertical { - get { return orientation == Gtk.Orientation.VERTICAL; } - set { orientation = value ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL; } - } - - // emitted when the user drags the slider - public signal void dragged (); - - construct { - draw_value = false; - - if (adjustment == null) - adjustment = new Gtk.Adjustment(0,0,0,0,0,0); - - if (max == 0 && min == 0) { - max = 1; - } - - if (step == 0) { - step = 0.05; - } - - notify["orientation"].connect(() => { - notify_property("vertical"); - }); - - button_press_event.connect(() => { dragging = true; }); - key_press_event.connect(() => { dragging = true; }); - button_release_event.connect(() => { dragging = false; }); - key_release_event.connect(() => { dragging = false; }); - scroll_event.connect((event) => { - dragging = true; - if (event.delta_y > 0) - value -= step; - else - value += step; - dragging = false; - }); - - value_changed.connect(() => { - if (dragging) - dragged(); - }); - } - - public bool dragging { get; private set; } - - public double value { - get { return adjustment.value; } - set { if (!dragging) adjustment.value = value; } - } - - public double min { - get { return adjustment.lower; } - set { adjustment.lower = value; } - } - - public double max { - get { return adjustment.upper; } - set { adjustment.upper = value; } - } - - public double step { - get { return adjustment.step_increment; } - set { adjustment.step_increment = value; } - } - - // TODO: marks -} -} diff --git a/core/src/widget/stack.vala b/core/src/widget/stack.vala deleted file mode 100644 index 02f9959..0000000 --- a/core/src/widget/stack.vala +++ /dev/null @@ -1,26 +0,0 @@ -public class Astal.Stack : Gtk.Stack { - public string shown { - get { return visible_child_name; } - set { visible_child_name = value; } - } - - public List<weak Gtk.Widget> children { - set { _set_children(value); } - owned get { return get_children(); } - } - - private void _set_children(List<weak Gtk.Widget> arr) { - foreach(var child in get_children()) { - remove(child); - } - - var i = 0; - foreach(var child in arr) { - if (child.name != null) { - add_named(child, child.name); - } else { - add_named(child, (++i).to_string()); - } - } - } -} diff --git a/core/src/widget/widget.vala b/core/src/widget/widget.vala deleted file mode 100644 index 2506bc8..0000000 --- a/core/src/widget/widget.vala +++ /dev/null @@ -1,157 +0,0 @@ -namespace Astal { -private class Css { - private static HashTable<Gtk.Widget, Gtk.CssProvider> _providers; - public static HashTable<Gtk.Widget, Gtk.CssProvider> providers { - get { - if (_providers == null) { - _providers = new HashTable<Gtk.Widget, Gtk.CssProvider>( - (w) => (uint)w, - (a, b) => a == b); - } - - return _providers; - } - } -} - -private void remove_provider(Gtk.Widget widget) { - var providers = Css.providers; - - if (providers.contains(widget)) { - var p = providers.get(widget); - widget.get_style_context().remove_provider(p); - providers.remove(widget); - p.dispose(); - } -} - -public void widget_set_css(Gtk.Widget widget, string css) { - var providers = Css.providers; - - if (providers.contains(widget)) { - remove_provider(widget); - } else { - widget.destroy.connect(() => { - remove_provider(widget); - }); - } - - var style = !css.contains("{") || !css.contains("}") - ? "* { ".concat(css, "}") : css; - - var p = new Gtk.CssProvider(); - widget.get_style_context() - .add_provider(p, Gtk.STYLE_PROVIDER_PRIORITY_USER); - - try { - p.load_from_data(style, style.length); - providers.set(widget, p); - } catch (Error err) { - warning(err.message); - } -} - -public string widget_get_css(Gtk.Widget widget) { - var providers = Css.providers; - - if (providers.contains(widget)) - return providers.get(widget).to_string(); - - return ""; -} - -public void widget_set_class_names(Gtk.Widget widget, string[] class_names) { - foreach (var name in widget_get_class_names(widget)) - widget_toggle_class_name(widget, name, false); - - foreach (var name in class_names) - widget_toggle_class_name(widget, name, true); -} - -public List<weak string> widget_get_class_names(Gtk.Widget widget) { - return widget.get_style_context().list_classes(); -} - -public void widget_toggle_class_name( - Gtk.Widget widget, - string class_name, - bool condition = true -) { - var c = widget.get_style_context(); - if (condition) - c.add_class(class_name); - else - c.remove_class(class_name); -} - -private class Cursor { - private static HashTable<Gtk.Widget, string> _cursors; - public static HashTable<Gtk.Widget, string> cursors { - get { - if (_cursors == null) { - _cursors = new HashTable<Gtk.Widget, string>( - (w) => (uint)w, - (a, b) => a == b); - } - return _cursors; - } - } -} - -private void widget_setup_cursor(Gtk.Widget widget) { - widget.add_events(Gdk.EventMask.ENTER_NOTIFY_MASK); - widget.add_events(Gdk.EventMask.LEAVE_NOTIFY_MASK); - widget.enter_notify_event.connect(() => { - widget.get_window().set_cursor( - new Gdk.Cursor.from_name( - Gdk.Display.get_default(), - Cursor.cursors.get(widget))); - return false; - }); - widget.leave_notify_event.connect(() => { - widget.get_window().set_cursor( - new Gdk.Cursor.from_name( - Gdk.Display.get_default(), - "default")); - return false; - }); - widget.destroy.connect(() => { - if (Cursor.cursors.contains(widget)) - Cursor.cursors.remove(widget); - }); -} - -public void widget_set_cursor(Gtk.Widget widget, string cursor) { - if (!Cursor.cursors.contains(widget)) - widget_setup_cursor(widget); - - Cursor.cursors.set(widget, cursor); -} - -public string widget_get_cursor(Gtk.Widget widget) { - return Cursor.cursors.get(widget); -} - -private class ClickThrough { - private static HashTable<Gtk.Widget, bool> _click_through; - public static HashTable<Gtk.Widget, bool> click_through { - get { - if (_click_through == null) { - _click_through = new HashTable<Gtk.Widget, bool>( - (w) => (uint)w, - (a, b) => a == b); - } - return _click_through; - } - } -} - -public void widget_set_click_through(Gtk.Widget widget, bool click_through) { - ClickThrough.click_through.set(widget, click_through); - widget.input_shape_combine_region(click_through ? new Cairo.Region() : null); -} - -public bool widget_get_click_through(Gtk.Widget widget) { - return ClickThrough.click_through.get(widget); -} -} diff --git a/core/src/widget/window.vala b/core/src/widget/window.vala deleted file mode 100644 index f1a377f..0000000 --- a/core/src/widget/window.vala +++ /dev/null @@ -1,255 +0,0 @@ -using GtkLayerShell; - -namespace Astal { -public enum WindowAnchor { - NONE = 0, - TOP = 1, - RIGHT = 2, - LEFT = 4, - BOTTOM = 8, -} - -public enum Exclusivity { - NORMAL, - EXCLUSIVE, - IGNORE, -} - -public enum Layer { - BACKGROUND = 0, // GtkLayerShell.Layer.BACKGROUND - BOTTOM = 1, // GtkLayerShell.Layer.BOTTOM - TOP = 2, // GtkLayerShell.Layer.TOP - OVERLAY = 3, // GtkLayerShell.Layer.OVERLAY -} - -public enum Keymode { - NONE = 0, // GtkLayerShell.KeyboardMode.NONE - ON_DEMAND = 1, // GtkLayerShell.KeyboardMode.ON_DEMAND - EXCLUSIVE = 2, // GtkLayerShell.KeyboardMode.EXCLUSIVE -} - -public class Window : Gtk.Window { - private static bool check(string action) { - if (!is_supported()) { - critical(@"can not $action on window: layer shell not supported"); - print("tip: running from an xwayland terminal can cause this, for example VsCode"); - return true; - } - return false; - } - - private InhibitManager? inhibit_manager; - private Inhibitor? inhibitor; - - construct { - if (check("initialize layer shell")) - return; - - height_request = 1; - width_request = 1; - init_for_window(this); - inhibit_manager = InhibitManager.get_default(); - } - - public bool inhibit { - set { - if (inhibit_manager == null) { - return; - } - if (value && inhibitor == null) { - inhibitor = inhibit_manager.inhibit(this); - } - else if (!value && inhibitor != null) { - inhibitor = null; - } - } - get { - return inhibitor != null; - } - } - - public override void show() { - base.show(); - if(inhibit) { - inhibitor = inhibit_manager.inhibit(this); - } - } - - public string namespace { - get { return get_namespace(this); } - set { set_namespace(this, value); } - } - - public int anchor { - set { - if (check("set anchor")) - return; - - set_anchor(this, Edge.TOP, WindowAnchor.TOP in value); - set_anchor(this, Edge.BOTTOM, WindowAnchor.BOTTOM in value); - set_anchor(this, Edge.LEFT, WindowAnchor.LEFT in value); - set_anchor(this, Edge.RIGHT, WindowAnchor.RIGHT in value); - } - get { - var a = WindowAnchor.NONE; - if (get_anchor(this, Edge.TOP)) - a = a | WindowAnchor.TOP; - - if (get_anchor(this, Edge.RIGHT)) - a = a | WindowAnchor.RIGHT; - - if (get_anchor(this, Edge.LEFT)) - a = a | WindowAnchor.LEFT; - - if (get_anchor(this, Edge.BOTTOM)) - a = a | WindowAnchor.BOTTOM; - - return a; - } - } - - public Exclusivity exclusivity { - set { - if (check("set exclusivity")) - return; - - switch (value) { - case Exclusivity.NORMAL: - set_exclusive_zone(this, 0); - break; - case Exclusivity.EXCLUSIVE: - auto_exclusive_zone_enable(this); - break; - case Exclusivity.IGNORE: - set_exclusive_zone(this, -1); - break; - } - } - get { - if (auto_exclusive_zone_is_enabled(this)) - return Exclusivity.EXCLUSIVE; - - if (get_exclusive_zone(this) == -1) - return Exclusivity.IGNORE; - - return Exclusivity.NORMAL; - } - } - - public Layer layer { - get { return (Layer)get_layer(this); } - set { - if (check("set layer")) - return; - - set_layer(this, (GtkLayerShell.Layer)value); - } - } - - public Keymode keymode { - get { return (Keymode)get_keyboard_mode(this); } - set { - if (check("set keymode")) - return; - - set_keyboard_mode(this, (GtkLayerShell.KeyboardMode)value); - } - } - - public Gdk.Monitor gdkmonitor { - get { return get_monitor(this); } - set { - if (check("set gdkmonitor")) - return; - - set_monitor (this, value); - } - } - - public new int margin_top { - get { return GtkLayerShell.get_margin(this, Edge.TOP); } - set { - if (check("set margin_top")) - return; - - GtkLayerShell.set_margin(this, Edge.TOP, value); - } - } - - public new int margin_bottom { - get { return GtkLayerShell.get_margin(this, Edge.BOTTOM); } - set { - if (check("set margin_bottom")) - return; - - GtkLayerShell.set_margin(this, Edge.BOTTOM, value); - } - } - - public new int margin_left { - get { return GtkLayerShell.get_margin(this, Edge.LEFT); } - set { - if (check("set margin_left")) - return; - - GtkLayerShell.set_margin(this, Edge.LEFT, value); - } - } - - public new int margin_right { - get { return GtkLayerShell.get_margin(this, Edge.RIGHT); } - set { - if (check("set margin_right")) - return; - - GtkLayerShell.set_margin(this, Edge.RIGHT, value); - } - } - - public new int margin { - set { - if (check("set margin")) - return; - - margin_top = value; - margin_right = value; - margin_bottom = value; - margin_left = value; - } - } - - /** - * CAUTION: the id might not be the same mapped by the compositor - * to reset and let the compositor map it pass a negative number - */ - public int monitor { - set { - if (check("set monitor")) - return; - - if (value < 0) - set_monitor(this, (Gdk.Monitor)null); - - var m = Gdk.Display.get_default().get_monitor(value); - set_monitor(this, m); - } - get { - var m = get_monitor(this); - var d = Gdk.Display.get_default(); - for (var i = 0; i < d.get_n_monitors(); ++i) { - if (m == d.get_monitor(i)) - return i; - } - - return -1; - } - } -} - -/** - * CAUTION: the id might not be the same mapped by the compositor - */ -public uint get_num_monitors() { - return Gdk.Display.get_default().get_n_monitors(); -} -} |