| 1 |
/* |
| 2 |
* Copyright (c) 2017-2019 José Amuedo (https://github.com/spheras) |
| 3 |
* |
| 4 |
* This program is free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation, either version 3 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
/** |
| 19 |
* @class |
| 20 |
* Desktop Manager |
| 21 |
*/ |
| 22 |
public class DesktopFolder.DesktopManager : DesktopFolder.FolderManager { |
| 23 |
|
| 24 |
/** |
| 25 |
* @constructor |
| 26 |
* @param DesktopFolderApp application the application owner of this window |
| 27 |
* @param string folder_name the name of the folder |
| 28 |
*/ |
| 29 |
public DesktopManager (DesktopFolderApp application) { |
| 30 |
// first, let's check the folder |
| 31 |
var directory = File.new_for_path (DesktopFolderApp.get_app_folder ()); // + "/" + DesktopFolder.DesktopWindow.DESKTOP_FAKE_FOLDER_NAME); |
| 32 |
if (!directory.query_exists ()) { |
| 33 |
DirUtils.create (directory.get_path (), 0755); |
| 34 |
} |
| 35 |
|
| 36 |
base (application, ""); |
| 37 |
|
| 38 |
// we cannot be moved |
| 39 |
this.is_moveable = false; |
| 40 |
this.get_view ().set_type_hint (Gdk.WindowTypeHint.DOCK); |
| 41 |
this.get_view ().change_body_color (0); |
| 42 |
|
| 43 |
Gdk.Screen screen = Gdk.Screen.get_default (); |
| 44 |
this.on_screen_size_changed (screen); |
| 45 |
|
| 46 |
this.view.show (); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* @overrided |
| 51 |
*/ |
| 52 |
public override int get_parent_default_arrangement_orientation_setting () { |
| 53 |
return FolderSettings.ARRANGEMENT_ORIENTATION_VERTICAL; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* @name create_view |
| 58 |
* @description create the view associated with this manager |
| 59 |
* @overrided |
| 60 |
*/ |
| 61 |
protected override void create_view () { |
| 62 |
this.view = new DesktopFolder.DesktopWindow (this); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* @name show_items |
| 67 |
* @description shows the items |
| 68 |
*/ |
| 69 |
public override void show_items () { |
| 70 |
// debug (@"show_items $(this.get_application ().get_desktop_visibility ())"); |
| 71 |
if (this.get_application ().get_desktop_visibility ()) { |
| 72 |
// debug ("showing items"); |
| 73 |
base.show_items (); |
| 74 |
base.view.refresh (); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* @name hide_items |
| 80 |
* @description hides the items |
| 81 |
*/ |
| 82 |
public override void hide_items () { |
| 83 |
debug (@"hide_items $(this.get_application ().get_desktop_visibility ())"); |
| 84 |
debug ("hiding items"); |
| 85 |
base.hide_items (); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* @name show_view |
| 90 |
* @description show the items on the desktop |
| 91 |
* @override |
| 92 |
*/ |
| 93 |
public override void show_view () { |
| 94 |
this.show_items (); |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* @name hide_view |
| 99 |
* @description hide the items on the desktop |
| 100 |
* @override |
| 101 |
*/ |
| 102 |
public override void hide_view () { |
| 103 |
this.hide_items (); |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* @name on_screen_size_changed |
| 108 |
* @description detecting screen size changes |
| 109 |
*/ |
| 110 |
public override void on_screen_size_changed (Gdk.Screen screen) { |
| 111 |
if (screen == null) { |
| 112 |
screen = Gdk.Screen.get_default (); |
| 113 |
} |
| 114 |
|
| 115 |
Gdk.Rectangle boundingbox = DesktopFolder.Util.get_desktop_bounding_box (); |
| 116 |
// debug ("bounding box result: %d,%d -- %d,%d", boundingbox.x, boundingbox.y, boundingbox.width, boundingbox.height); |
| 117 |
|
| 118 |
int[] borders = this.get_dock_borders (); |
| 119 |
|
| 120 |
this.get_view ().move (borders[0], borders[2]); // (-12, -10); |
| 121 |
int w = boundingbox.width - borders[0]; // deprecated -> screen.get_width (); // + 25; |
| 122 |
int h = boundingbox.height - borders[2]; // deprecated -> screen.get_height (); // + 25; |
| 123 |
this.get_view ().resize (w, h); |
| 124 |
this.get_view ().set_default_size (w, h); |
| 125 |
this.get_view ().height_request = h; |
| 126 |
this.get_view ().width_request = w; |
| 127 |
|
| 128 |
debug ("DESKTOP SIZE CHANGED! (%d,%d) (%d,%d)", 0, 0, w, h); |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* @name get_dock_borders |
| 133 |
* @description return an array with the space needed for system docks, i.e. plank |
| 134 |
* @return {int[]} the array with space needed [left, right, top, bottom] |
| 135 |
*/ |
| 136 |
public int[] get_dock_borders () { |
| 137 |
unowned Wnck.Screen screen = Wnck.Screen.get_default (); |
| 138 |
while (Gtk.events_pending ()) { |
| 139 |
Gtk.main_iteration (); |
| 140 |
} |
| 141 |
unowned List <Wnck.Window> windows = screen.get_windows (); |
| 142 |
Gee.List <Wnck.Window> docks = new Gee.ArrayList <Wnck.Window>(); |
| 143 |
int[] borders = new int[4]; |
| 144 |
foreach (Wnck.Window w in windows) { |
| 145 |
Wnck.Application window_app = w.get_application (); |
| 146 |
string app_name = window_app.get_name (); |
| 147 |
if (w.get_window_type () == Wnck.WindowType.DOCK && app_name.index_of ("desktopfolder") < 0) { |
| 148 |
var name = w.get_name (); |
| 149 |
debug ("Dock window found: %s", name); |
| 150 |
docks.add (w); |
| 151 |
string[] strut = this.get_strut (w.get_xid ()); |
| 152 |
if (strut != null) { |
| 153 |
// we get the greatest border |
| 154 |
for (int i = 0; i < 4; i++) { |
| 155 |
int istrut = int.parse (strut[i]); |
| 156 |
if (borders[i] < istrut) { |
| 157 |
borders[i] = istrut; |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
return borders; |
| 165 |
} |
| 166 |
|
| 167 |
/** |
| 168 |
* @name ge_strut |
| 169 |
* @description get the strut- values from xprop, on dock type windows. |
| 170 |
* This function is inspired in the function for Ubuntu Budgie Window Shuffler |
| 171 |
* It is based on the xprop command, check it by using: xprop -id {xid of the window} |
| 172 |
* https://github.com/UbuntuBudgie/window-shuffler/blob/c2df9934fd823f50a2409effccd8349654bf7b5e/shuffler_geo.py#L62 |
| 173 |
* @param {ulong} xid the x id of the window |
| 174 |
* @return {string[]} the strut info (or null). An array of 4 positions [left,right,top,bottom] |
| 175 |
*/ |
| 176 |
private string[] ? get_strut (ulong xid) { |
| 177 |
// get the strut- values from xprop, on dock type windows. Since Plank is |
| 178 |
// an exception, the function indicates if the dock is a plank instance. |
| 179 |
string output; |
| 180 |
string cmd = "xprop -id %d".printf ((int) xid); |
| 181 |
const string STRUT_CARDINAL = "_NET_WM_STRUT(CARDINAL) = "; |
| 182 |
GLib.Process.spawn_command_line_sync (cmd, out output); |
| 183 |
string[] all_lines = output.split ("\n"); |
| 184 |
foreach (string l in all_lines) { |
| 185 |
// debug("XPROP: %s",l); |
| 186 |
if (l.index_of (STRUT_CARDINAL, 0) >= 0) { |
| 187 |
return l.split ("=")[1].split (","); |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
return null; |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* @name skip_file |
| 196 |
* @description we must skip the widget setting files |
| 197 |
* @override |
| 198 |
*/ |
| 199 |
protected override bool skip_file (File file) { |
| 200 |
string basename = file.get_basename (); |
| 201 |
|
| 202 |
if (FileUtils.test (file.get_path (), FileTest.IS_DIR)) { |
| 203 |
// is a panel? |
| 204 |
string flagfilepath = file.get_path () + "/.desktopfolder"; |
| 205 |
// debug("is a panel? %s",flagfilepath); |
| 206 |
File flagfile = File.new_for_commandline_arg (flagfilepath); |
| 207 |
return flagfile.query_exists (); |
| 208 |
} else { |
| 209 |
if (basename.has_suffix (DesktopFolder.OLD_NOTE_EXTENSION) || basename.has_suffix (DesktopFolder.OLD_PHOTO_EXTENSION) |
| 210 |
|| basename.has_suffix (DesktopFolder.NEW_NOTE_EXTENSION) || basename.has_suffix (DesktopFolder.NEW_PHOTO_EXTENSION)) { |
| 211 |
return true; |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
return base.skip_file (file); |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* @overrided |
| 220 |
* we must create a .nopanel inside to avoid creating a panel from this folder |
| 221 |
*/ |
| 222 |
protected override void create_new_folder_inside (string folder_path) { |
| 223 |
File nopanel = File.new_for_path (folder_path + "/.nopanel"); |
| 224 |
try { |
| 225 |
if (!nopanel.query_exists ()) { |
| 226 |
nopanel.create (FileCreateFlags.NONE); |
| 227 |
} |
| 228 |
} catch (Error e) { |
| 229 |
stderr.printf ("Error: %s\n", e.message); |
| 230 |
Util.show_error_dialog ("Error", e.message); |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
} |