Skip to content

Instantly share code, notes, and snippets.

@NepNet
Last active January 24, 2017 11:30
Show Gist options
  • Select an option

  • Save NepNet/29a6b38ff584b5e7a70c72a1e1ed5b29 to your computer and use it in GitHub Desktop.

Select an option

Save NepNet/29a6b38ff584b5e7a70c72a1e1ed5b29 to your computer and use it in GitHub Desktop.
//------------------------------------------------------------------//
// This is a modified version of Xlib class from Docky to be used--//
// to reserve screen space for dock-type apps----------------------//
//------------------------------------------------------------------//
using System;
using System.Runtime.InteropServices;
namespace Gtk
{
public static class XLib
{
public enum Position
{
Bottom,
Left,
Top,
Right
}
public enum Struts
{
Left = 0,
Right = 1,
Top = 2,
Bottom = 3,
LeftStart = 4,
LeftEnd = 5,
RightStart = 6,
RightEnd = 7,
TopStart = 8,
TopEnd = 9,
BottomStart = 10,
BottomEnd = 11
}
const string libX11 = "libX11";
const string libGdkX11 = "libgdk-x11-2.0";
[DllImport (libGdkX11)]
static extern IntPtr gdk_x11_drawable_get_xid (IntPtr handle);
[DllImport (libGdkX11)]
static extern IntPtr gdk_x11_drawable_get_xdisplay (IntPtr handle);
[DllImport (libGdkX11)]
static extern IntPtr gdk_x11_display_get_xdisplay (IntPtr display);
[DllImport (libX11)]
public extern static IntPtr XOpenDisplay (IntPtr display);
[DllImport (libX11)]
public extern static int XInternAtoms (IntPtr display, string[] atom_names, int atom_count, bool only_if_exists, IntPtr[] atoms);
[DllImport (libX11)]
extern static int XChangeProperty (IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, int mode, IntPtr[] data, int nelements);
[DllImport (libX11)]
public extern static int XGetWindowProperty (IntPtr display, IntPtr window, IntPtr atom, IntPtr long_offset,
IntPtr long_length, bool delete, IntPtr req_type, out IntPtr actual_type,
out int actual_format, out IntPtr nitems, out IntPtr bytes_after, out IntPtr prop);
public static IntPtr GdkWindowX11Xid (Gdk.Window window)
{
return gdk_x11_drawable_get_xid (window.Handle);
}
public static IntPtr GdkDrawableXDisplay (Gdk.Window window)
{
return gdk_x11_drawable_get_xdisplay (window.Handle);
}
public static IntPtr GdkDisplayXDisplay (Gdk.Display display)
{
return gdk_x11_display_get_xdisplay (display.Handle);
}
public static int XChangeProperty (Gdk.Window window, IntPtr property, IntPtr type, int mode, IntPtr[] data)
{
return XChangeProperty (GdkDrawableXDisplay (window), GdkWindowX11Xid (window), property, type, 32, mode, data, data.Length);
}
public static void ReserveScreen (Gtk.Window window ,Position position, int size)
{
X11Atoms atoms = X11Atoms.Instance;
Gdk.Screen screen = window.Screen;
int Monitor;
Monitor = screen.Number;
Gdk.Rectangle monitor_geo;
monitor_geo = screen.GetMonitorGeometry (Monitor);
IntPtr [] struts = new IntPtr [12];
IntPtr [] first_struts = new [] { struts [0], struts [1], struts [2], struts [3] };
switch (position) {
case Position.Bottom:
{
struts [(int) Struts.Bottom] = (IntPtr) (size + (screen.Height - (monitor_geo.Y + monitor_geo.Height)));
struts [(int) Struts.BottomStart] = (IntPtr) monitor_geo.X;
struts [(int) Struts.BottomEnd] = (IntPtr) (monitor_geo.X + monitor_geo.Width - 1);
}
break;
case Position.Left:
{
struts [(int)Struts.Left] = (IntPtr)(monitor_geo.X + size);
struts [(int)Struts.LeftStart] = (IntPtr)monitor_geo.Y;
struts [(int)Struts.LeftEnd] = (IntPtr)(monitor_geo.Y + monitor_geo.Height - 1);
}
break;
case Position.Top:
{
struts [(int)Struts.Top] = (IntPtr)(size + monitor_geo.Y);
struts [(int)Struts.TopStart] = (IntPtr)monitor_geo.X;
struts [(int)Struts.TopEnd] = (IntPtr)(monitor_geo.X + monitor_geo.Width - 1);
}
break;
case Position.Right:
{
struts [(int) Struts.Right] = (IntPtr) (size + (screen.Width - (monitor_geo.X + monitor_geo.Width)));
struts [(int) Struts.RightStart] = (IntPtr) monitor_geo.Y;
struts [(int) Struts.RightEnd] = (IntPtr) (monitor_geo.Y + monitor_geo.Height - 1);
}
break;
default:
Console.WriteLine ("Error");
break;
}
XChangeProperty (window.GdkWindow, atoms._NET_WM_STRUT_PARTIAL, (IntPtr)6,
0, struts);
XChangeProperty (window.GdkWindow, atoms._NET_WM_STRUT, (IntPtr)6,
0, first_struts);
}
}
public class X11Atoms {
static X11Atoms instance;
public static X11Atoms Instance {
get {
if (instance == null)
instance = new X11Atoms (Gdk.Screen.Default.Display);
return instance;
}
}
public readonly IntPtr _NET_WM_STRUT;
public readonly IntPtr _NET_WM_STRUT_PARTIAL;
X11Atoms (Gdk.Display dsp) {
IntPtr display = XLib.GdkDisplayXDisplay (dsp);
// make sure this array stays in sync with the statements below
string [] atom_names = new string[] {
"WM_PROTOCOLS",
"WM_DELETE_WINDOW",
"WM_TAKE_FOCUS",
"_NET_SUPPORTED",
"_NET_CLIENT_LIST",
"_NET_NUMBER_OF_DESKTOPS",
"_NET_DESKTOP_GEOMETRY",
"_NET_DESKTOP_VIEWPORT",
"_NET_CURRENT_DESKTOP",
"_NET_DESKTOP_NAMES",
"_NET_ACTIVE_WINDOW",
"_NET_WORKAREA",
"_NET_SUPPORTING_WM_CHECK",
"_NET_VIRTUAL_ROOTS",
"_NET_DESKTOP_LAYOUT",
"_NET_SHOWING_DESKTOP",
"_NET_CLOSE_WINDOW",
"_NET_MOVERESIZE_WINDOW",
"_NET_WM_MOVERESIZE",
"_NET_RESTACK_WINDOW",
"_NET_REQUEST_FRAME_EXTENTS",
"_NET_WM_NAME",
"_NET_WM_VISIBLE_NAME",
"_NET_WM_ICON_NAME",
"_NET_WM_VISIBLE_ICON_NAME",
"_NET_WM_DESKTOP",
"_NET_WM_WINDOW_TYPE",
"_NET_WM_STATE",
"_NET_WM_ALLOWED_ACTIONS",
"_NET_WM_STRUT",
"_NET_WM_STRUT_PARTIAL",
"_NET_WM_ICON_GEOMETRY",
"_NET_WM_ICON",
"_NET_WM_PID",
"_NET_WM_HANDLED_ICONS",
"_NET_WM_USER_TIME",
"_NET_FRAME_EXTENTS",
"_NET_WM_PING",
"_NET_WM_SYNC_REQUEST",
"_NET_SYSTEM_TRAY_OPCODE",
"_NET_SYSTEM_TRAY_ORIENTATION",
"_NET_WM_STATE_MAXIMIZED_HORZ",
"_NET_WM_STATE_MAXIMIZED_VERT",
"_NET_WM_STATE_HIDDEN",
"_XEMBED",
"_XEMBED_INFO",
"_MOTIF_WM_HINTS",
"_NET_WM_STATE_SKIP_TASKBAR",
"_NET_WM_STATE_ABOVE",
"_NET_WM_STATE_MODAL",
"_NET_WM_CONTEXT_HELP",
"_NET_WM_WINDOW_OPACITY",
"_NET_WM_WINDOW_TYPE_DESKTOP",
"_NET_WM_WINDOW_TYPE_DOCK",
"_NET_WM_WINDOW_TYPE_TOOLBAR",
"_NET_WM_WINDOW_TYPE_MENU",
"_NET_WM_WINDOW_TYPE_UTILITY",
"_NET_WM_WINDOW_TYPE_DIALOG",
"_NET_WM_WINDOW_TYPE_SPLASH",
"_NET_WM_WINDOW_TYPE_NORMAL",
"_COMPIZ_WM_WINDOW_BLUR",
"CLIPBOARD",
"PRIMARY",
"COMPOUND_TEXT",
"UTF8_STRING",
"TARGETS",
"_SWF_AsyncAtom",
"_SWF_PostMessageAtom",
"_SWF_HoverAtom",
};
IntPtr[] atoms = new IntPtr [atom_names.Length];;
Console.WriteLine (atom_names.Length);
XLib.XInternAtoms (display, atom_names, 69, false, atoms);
_NET_WM_STRUT = atoms [29];
_NET_WM_STRUT_PARTIAL = atoms [30];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment