From af047d1b56c28f95d5ca3ea1f51fb6222c9a4c67 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 20 Sep 2017 11:06:19 +0300 Subject: [PATCH] Toplevel: split layout from core file. --- app/application.c | 3 +- lib/CMakeLists.txt | 1 + lib/applet-widget.c | 2 +- lib/configurator.vala | 34 +++++----- lib/dbusmenu | 2 +- lib/panel-layout.vala | 146 ++++++++++++++++++++++++++++++++++++++++ lib/panel-toplevel.vala | 139 +++++--------------------------------- 7 files changed, 184 insertions(+), 143 deletions(-) create mode 100644 lib/panel-layout.vala diff --git a/app/application.c b/app/application.c index f2f98475..a0827dac 100644 --- a/app/application.c +++ b/app/application.c @@ -476,7 +476,8 @@ static void activate_menu(GSimpleAction *simple, GVariant *param, gpointer data) { if (VALA_PANEL_IS_TOPLEVEL(l->data)) { - GList *applets = vala_panel_toplevel_get_applets_list(l->data); + ValaPanelLayout* layout = VALA_PANEL_TOPLEVEL(l->data)->layout; + GList *applets = vala_panel_layout_get_applets_list(layout); for (GList *il = applets; il != NULL; il = il->next) { GSimpleActionGroup *grp; diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index a7743b14..4a961bf5 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -46,6 +46,7 @@ set(VALA_FILES configurator.vala applet-holder.vala panel-toplevel.vala + panel-layout.vala ) vala_precompile(VALA_C ${LIBNAME} ${VALA_FILES} diff --git a/lib/applet-widget.c b/lib/applet-widget.c index 5b1731b6..ec190eea 100644 --- a/lib/applet-widget.c +++ b/lib/applet-widget.c @@ -131,7 +131,7 @@ static void activate_remove(GSimpleAction *act, GVariant *param, gpointer obj) * user manipulates the Configured Plugins list, after we remove this entry. * Close the configuration dialog if it is open. */ gtk_widget_destroy0(p->toplevel->pref_dialog); - vala_panel_toplevel_remove_applet(p->toplevel, self); + vala_panel_layout_remove_applet(p->toplevel->layout, self); } static GtkWidget *vala_panel_applet_get_config_dialog(ValaPanelApplet *self) { diff --git a/lib/configurator.vala b/lib/configurator.vala index 76873c41..4c2d7392 100644 --- a/lib/configurator.vala +++ b/lib/configurator.vala @@ -159,7 +159,7 @@ namespace ValaPanel if( tree_sel.get_selected(out model, out it ) ) { model.get(it, Column.DATA, out pl, -1 ); - var desc = Toplevel.holder.get_plugin(pl,Toplevel.core_settings).plugin_info.get_description(); + var desc = Layout.holder.get_plugin(pl,Toplevel.core_settings).plugin_info.get_description(); plugin_desc.set_text(_(desc) ); configure_button.set_sensitive(pl.is_configurable()); } @@ -174,11 +174,11 @@ namespace ValaPanel Applet pl; bool expand; model.get(it, Column.DATA, out pl, Column.EXPAND, out expand, -1 ); - if (Toplevel.holder.get_plugin(pl,Toplevel.core_settings).plugin_info.get_external_data(Data.EXPANDABLE)!=null) + if (Layout.holder.get_plugin(pl,Toplevel.core_settings).plugin_info.get_external_data(Data.EXPANDABLE)!=null) { expand = !expand; (model as Gtk.ListStore).set(it,Column.EXPAND,expand,-1); - unowned UnitSettings s = toplevel.get_applet_settings(pl); + unowned UnitSettings s = toplevel.layout.get_applet_settings(pl); s.default_settings.set_boolean(Key.EXPAND,expand); } } @@ -189,19 +189,19 @@ namespace ValaPanel * The g_object_set method is touchy about its parameter, so we can't pass the boolean directly. */ Applet pl; model.get(iter, Column.DATA, out pl, -1); - renderer.visible = (Toplevel.holder.get_plugin(pl,Toplevel.core_settings).plugin_info.get_external_data(Data.EXPANDABLE)!=null) ? true : false; + renderer.visible = (Layout.holder.get_plugin(pl,Toplevel.core_settings).plugin_info.get_external_data(Data.EXPANDABLE)!=null) ? true : false; } private void update_plugin_list_model() { TreeIter it; var list = new Gtk.ListStore( 3, typeof(string), typeof(bool), typeof(Applet) ); - var plugins = toplevel.get_applets_list(); + var plugins = toplevel.layout.get_applets_list(); foreach(var widget in plugins) { var w = widget as Applet; var expand = widget.hexpand && widget.vexpand; list.append(out it ); - var name = Toplevel.holder.get_plugin(w,Toplevel.core_settings).plugin_info.get_name(); + var name = Layout.holder.get_plugin(w,Toplevel.core_settings).plugin_info.get_name(); list.set(it, Column.NAME, _(name), Column.EXPAND, expand, @@ -294,7 +294,7 @@ namespace ValaPanel /* Populate list of available plugins. * Omit plugins that can only exist once per system if it is already configured. */ - foreach(var type in Toplevel.holder.get_all_types()) + foreach(var type in Layout.holder.get_all_types()) { var once = type.get_external_data(Data.ONE_PER_SYSTEM); if (once == null || !type.is_loaded()) @@ -320,8 +320,8 @@ namespace ValaPanel { string type; list.get(it, 1, out type, -1 ); - toplevel.add_applet(type); - toplevel.update_applet_positions(); + toplevel.layout.add_applet(type); + toplevel.layout.update_applet_positions(); update_plugin_list_model(); } update_widget_position_keys(); @@ -350,16 +350,16 @@ namespace ValaPanel (model as Gtk.ListStore).remove(it); #endif tree_sel.select_path(tree_path ); - toplevel.remove_applet(pl); + toplevel.layout.remove_applet(pl); } } private void update_widget_position_keys() { - foreach(var w in toplevel.get_applets_list()) + foreach(var w in toplevel.layout.get_applets_list()) { var applet = w as Applet; - uint idx = toplevel.get_applet_position(applet); - unowned UnitSettings s = toplevel.get_applet_settings(applet); + uint idx = toplevel.layout.get_applet_position(applet); + unowned UnitSettings s = toplevel.layout.get_applet_settings(applet); s.default_settings.set_uint(Key.POSITION,idx); } } @@ -381,12 +381,12 @@ namespace ValaPanel model.get(it, Column.DATA, out pl, -1 ); (model as Gtk.ListStore).move_before(ref it, prev ); - var i = toplevel.get_applet_position(pl); + var i = toplevel.layout.get_applet_position(pl); /* reorder in config, 0 is Global */ i = i > 0 ? i : 0; /* reorder in panel */ - toplevel.set_applet_position(pl,(int)i-1); + toplevel.layout.set_applet_position(pl,(int)i-1); update_widget_position_keys(); return; } @@ -411,9 +411,9 @@ namespace ValaPanel (model as Gtk.ListStore).move_after(ref it, next ); - var i = toplevel.get_applet_position(pl); + var i = toplevel.layout.get_applet_position(pl); /* reorder in panel */ - toplevel.set_applet_position(pl,(int)i+1); + toplevel.layout.set_applet_position(pl,(int)i+1); update_widget_position_keys(); } } diff --git a/lib/dbusmenu b/lib/dbusmenu index ad2d94bd..1c695380 160000 --- a/lib/dbusmenu +++ b/lib/dbusmenu @@ -1 +1 @@ -Subproject commit ad2d94bd9f37aa07292a0a0471b4ed3fecd52fcd +Subproject commit 1c6953804477e9ea12f68e037d9a04bd51e8aad9 diff --git a/lib/panel-layout.vala b/lib/panel-layout.vala new file mode 100644 index 00000000..79614bb2 --- /dev/null +++ b/lib/panel-layout.vala @@ -0,0 +1,146 @@ +/* + * vala-panel + * Copyright (C) 2017 Konstantin Pugin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License + * along with this program. If not, see . + */ + +using GLib; +using Gtk; +using Gdk; +using Config; + +namespace ValaPanel +{ + public class Layout : Gtk.Box + { + private static unowned CoreSettings core_settings = null; + internal static AppletHolder holder = null; + public string toplevel_id {get; construct;} + public Layout(ValaPanel.Toplevel top, Gtk.Orientation orient, int spacing) + { + Object(orientation: orient, + spacing: spacing, + baseline_position: BaselinePosition.CENTER, + border_width: 0, hexpand: true, vexpand: true, + toplevel_id: top.uuid); + } + static construct + { + holder = new AppletHolder(); + core_settings = Toplevel.core_settings; + } + construct + { + holder.applet_ready_to_place.connect(on_applet_ready_to_place); + holder.applet_loaded.connect(on_applet_loaded); + } + internal void init_applets() + { + foreach(var unit in core_settings.core_settings.get_strv(ValaPanel.Settings.CORE_UNITS)) + { + unowned UnitSettings pl = core_settings.get_by_uuid(unit); + if (!pl.is_toplevel() && pl.default_settings.get_string(Settings.TOPLEVEL_ID) == this.toplevel_id) + holder.load_applet(pl); + } + } + internal void add_applet(string type) + { + unowned UnitSettings s = core_settings.add_unit_settings(type,false); + s.default_settings.set_string(Key.NAME,type); + s.default_settings.set_string(Settings.TOPLEVEL_ID,this.toplevel_id); + holder.load_applet(s); + } + private void on_applet_loaded(string type) + { + foreach (var unit in core_settings.core_settings.get_strv(Settings.CORE_UNITS)) + { + unowned UnitSettings pl = core_settings.get_by_uuid(unit); + if (!pl.is_toplevel() && pl.default_settings.get_string(Settings.TOPLEVEL_ID) == this.toplevel_id) + { + if (pl.default_settings.get_string(Key.NAME) == type) + { + place_applet(holder.applet_ref(type),pl); + update_applet_positions(); + return; + } + } + } + } + private void on_applet_ready_to_place(AppletPlugin applet_plugin, UnitSettings pl) + { + if (!pl.is_toplevel() && pl.default_settings.get_string(Settings.TOPLEVEL_ID) == this.toplevel_id) + place_applet(applet_plugin,pl); + } + + internal void place_applet(AppletPlugin applet_plugin, UnitSettings s) + { + var aw = applet_plugin.get_applet_widget(this.get_parent().get_parent() as ValaPanel.Toplevel,s.custom_settings,s.uuid); + unowned Applet applet = aw; + var position = s.default_settings.get_uint(Key.POSITION); + this.pack_start(applet,false, true); + this.reorder_child(applet,(int)position); + if (applet_plugin.plugin_info.get_external_data(Data.EXPANDABLE)!=null) + { + s.default_settings.bind(Key.EXPAND,applet,"hexpand",GLib.SettingsBindFlags.GET); + applet.bind_property("hexpand",applet,"vexpand",BindingFlags.SYNC_CREATE); + } + applet.destroy.connect(()=>{ + string uuid = applet.uuid; + applet_destroyed(uuid); + if (this.in_destruction()) + core_settings.remove_unit_settings(uuid); + }); + } + public void remove_applet(Applet applet) + { + unowned UnitSettings s = core_settings.get_by_uuid(applet.uuid); + applet.destroy(); + core_settings.remove_unit_settings_full(s.uuid, true); + } + internal void applet_destroyed(string uuid) + { + unowned UnitSettings s = core_settings.get_by_uuid(uuid); + var name = s.default_settings.get_string(Key.NAME); + holder.applet_unref(name); + } + internal void update_applet_positions() + { + var children = this.get_children(); + for (unowned List l = children; l != null; l = l.next) + { + var idx = get_applet_settings(l.data as Applet).default_settings.get_uint(Key.POSITION); + this.reorder_child((l.data as Applet),(int)idx); + } + } + public List get_applets_list() + { + return this.get_children(); + } + internal unowned UnitSettings get_applet_settings(Applet pl) + { + return core_settings.get_by_uuid(pl.uuid); + } + internal uint get_applet_position(Applet pl) + { + int res; + this.child_get(pl,"position",out res, null); + return (uint)res; + } + internal void set_applet_position(Applet pl, int pos) + { + this.reorder_child(pl,pos); + } + } +} diff --git a/lib/panel-toplevel.vala b/lib/panel-toplevel.vala index 1a33affb..6c8fef82 100644 --- a/lib/panel-toplevel.vala +++ b/lib/panel-toplevel.vala @@ -29,7 +29,7 @@ namespace ValaPanel * Core ----------------------------------------------------------------- ************************************************************************/ private unowned Gtk.Revealer ah_rev = null; - private unowned Gtk.Box box; + public unowned Layout layout; private Gtk.Menu context_menu; internal ConfigureDialog pref_dialog; private bool initialized; @@ -125,7 +125,7 @@ namespace ValaPanel str.append_printf("}\n"); /* Feature proposed: Panel Layout and Shadow */ //~ str.append_printf(".-vala-panel-shadow {\n"); - //~ str.append_printf(" box-shadow: 0 0 0 3px alpha(0.3, %s);\n",foreground_color); + //~ str.append_printf(" layout-shadow: 0 0 0 3px alpha(0.3, %s);\n",foreground_color); //~ str.append_printf(" border-style: none;\n margin: 3px;\n"); //~ str.append_printf("}\n"); str.append_printf(".-vala-panel-round-corners {\n"); @@ -246,110 +246,14 @@ namespace ValaPanel { return (this.orientation == Orientation.HORIZONTAL) ? SizeRequestMode.WIDTH_FOR_HEIGHT : SizeRequestMode.HEIGHT_FOR_WIDTH; } - - /************************************************************************************* - * Plugins stuff - *************************************************************************************/ + /************************************************************************************************ + * Constructors + ************************************************************************************************/ private static unowned Platform platform = null; internal static unowned CoreSettings core_settings = null; - internal static AppletHolder holder = null; private static ulong mon_handler = 0; private static ulong mon_rm_handler = 0; private unowned UnitSettings settings; - static construct - { - holder = new AppletHolder(); - } - internal void add_applet(string type) - { - unowned UnitSettings s = core_settings.add_unit_settings(type,false); - s.default_settings.set_string(Key.NAME,type); - s.default_settings.set_string(Settings.TOPLEVEL_ID,this.uuid); - holder.load_applet(s); - } - private void on_applet_loaded(string type) - { - foreach (var unit in core_settings.core_settings.get_strv(Settings.CORE_UNITS)) - { - unowned UnitSettings pl = core_settings.get_by_uuid(unit); - if (!pl.is_toplevel() && pl.default_settings.get_string(Settings.TOPLEVEL_ID) == this.uuid) - { - if (pl.default_settings.get_string(Key.NAME) == type) - { - place_applet(holder.applet_ref(type),pl); - update_applet_positions(); - return; - } - } - } - } - private void on_applet_ready_to_place(AppletPlugin applet_plugin, UnitSettings pl) - { - if (!pl.is_toplevel() && pl.default_settings.get_string(Settings.TOPLEVEL_ID) == this.uuid) - place_applet(applet_plugin,pl); - } - - internal void place_applet(AppletPlugin applet_plugin, UnitSettings s) - { - var aw = applet_plugin.get_applet_widget(this,s.custom_settings,s.uuid); - unowned Applet applet = aw; - var position = s.default_settings.get_uint(Key.POSITION); - box.pack_start(applet,false, true); - box.reorder_child(applet,(int)position); - if (applet_plugin.plugin_info.get_external_data(Data.EXPANDABLE)!=null) - { - s.default_settings.bind(Key.EXPAND,applet,"hexpand",GLib.SettingsBindFlags.GET); - applet.bind_property("hexpand",applet,"vexpand",BindingFlags.SYNC_CREATE); - } - applet.destroy.connect(()=>{ - string uuid = applet.uuid; - applet_destroyed(uuid); - if (this.in_destruction()) - core_settings.remove_unit_settings(uuid); - }); - } - public void remove_applet(Applet applet) - { - unowned UnitSettings s = core_settings.get_by_uuid(applet.uuid); - applet.destroy(); - core_settings.remove_unit_settings_full(s.uuid, true); - } - internal void applet_destroyed(string uuid) - { - unowned UnitSettings s = core_settings.get_by_uuid(uuid); - var name = s.default_settings.get_string(Key.NAME); - holder.applet_unref(name); - } - internal void update_applet_positions() - { - var children = box.get_children(); - for (unowned List l = children; l != null; l = l.next) - { - var idx = get_applet_settings(l.data as Applet).default_settings.get_uint(Key.POSITION); - box.reorder_child((l.data as Applet),(int)idx); - } - } - public List get_applets_list() - { - return box.get_children(); - } - internal unowned UnitSettings get_applet_settings(Applet pl) - { - return core_settings.get_by_uuid(pl.uuid); - } - internal uint get_applet_position(Applet pl) - { - int res; - box.child_get(pl,"position",out res, null); - return (uint)res; - } - internal void set_applet_position(Applet pl, int pos) - { - box.reorder_child(pl,pos); - } - /************************************************************************************************ - * Constructors - ************************************************************************************************/ [CCode (returns_floating_reference = true)] public Toplevel(Gtk.Application app, Platform platform, string name) { @@ -440,7 +344,7 @@ namespace ValaPanel this.set_visual(visual); this.notify.connect((s,p)=> { if (p.name == Key.GRAVITY) - if (box != null) box.set_orientation(orientation); + if (layout != null) layout.set_orientation(orientation); if (p.name == Key.AUTOHIDE && this.ah_rev != null) if (autohide) ah_hide(); else ah_show(); }); @@ -450,8 +354,6 @@ namespace ValaPanel if (p.name in anames) this.update_appearance(); }); - holder.applet_ready_to_place.connect(on_applet_ready_to_place); - holder.applet_loaded.connect(on_applet_loaded); this.add_action_entries(panel_entries,this); } /*************************************************************************** @@ -489,10 +391,10 @@ namespace ValaPanel Gdk.flush(); initialized = false; } - if (box != null) + if (layout != null) { - box.destroy(); - box = null; + layout.destroy(); + layout = null; } } @@ -505,32 +407,23 @@ namespace ValaPanel Gdk.EventMask.LEAVE_NOTIFY_MASK); this.realize(); var r = new Gtk.Revealer(); - var mbox = new Box(this.orientation,0); - box = mbox; + var mlayout = new Layout(this,this.orientation,0); + layout = mlayout; this.ah_rev = r; r.set_transition_type(RevealerTransitionType.CROSSFADE); r.notify["child-revealed"].connect(()=>{ - box.queue_draw(); + layout.queue_draw(); }); - r.add(box); - box.set_baseline_position(Gtk.BaselinePosition.CENTER); - box.set_border_width(0); - box.set_hexpand(true); - box.set_vexpand(true); + r.add(layout); this.add(r); r.show(); - box.show(); + layout.show(); + layout.init_applets(); this.ah_rev.set_reveal_child(true); this.set_type_hint((dock)? Gdk.WindowTypeHint.DOCK : Gdk.WindowTypeHint.NORMAL); - foreach(var unit in core_settings.core_settings.get_strv(ValaPanel.Settings.CORE_UNITS)) - { - unowned UnitSettings pl = core_settings.get_by_uuid(unit); - if (!pl.is_toplevel() && pl.default_settings.get_string(Settings.TOPLEVEL_ID) == this.uuid) - holder.load_applet(pl); - } this.show(); this.stick(); - update_applet_positions(); + layout.update_applet_positions(); this.present(); this.autohide = autohide; this.update_geometry();