//Background = "vgradient|0:DimGrey|1:Black";
//Background = "Transparent";
Foreground = "LightGrey";
- //MouseEnter = "{Background=SteelBlue;}";
- //MouseLeave = "{Background=Transparent;}";
+ MouseEnter = "{Background=SteelBlue;}";
+ MouseLeave = "{Background=Transparent;}";
//MouseEnter = "{Background = vgradient|0:SteelBlue|1:Jet;Foreground=White;}";
//MouseLeave = "{Foreground=LightGrey;Background=Transparent;}";
SelectionBackground = "Transparent";
<?xml version="1.0"?>
-<HorizontalStack>
<Popper Font="{./Font}" Caption="{./Caption}" Background="{./Background}" PopDirection="{./PopDirection}"
Foreground = "{./Foreground}" CanPop="{./HasChildren}" MouseClick="./onMI_Click"
IsPopped="{²./IsOpened}" PopWidth="{./PopWidth}" PopHeight="{./PopHeight}">
<Border Foreground="DimGrey" Width="{../PopWidth}" Height="{../PopHeight}" Background="vgradient|0:DimGrey|1:Black">
<VerticalStack Name="ItemsContainer"/>
</Border>
-</Popper>
-<Widget Background="Green" Width="5" Height="5" Visible="{./AutomaticOpening}"/>
-</HorizontalStack>
+</Popper>
\ No newline at end of file
Bottom,
Center,
}
+ public enum MouseCursor
+ {
+ Arrow,
+ IBeam,
+ Crosshair,
+ Circle,
+ Hand,
+ Move,
+ Wait,
+ H,
+ V,
+ Top,
+ TopLeft,
+ TopRight,
+ Left,
+ Right,
+ BottomLeft,
+ Bottom,
+ BottomRight,
+ NW,
+ NE,
+ SW,
+ SE,
+ }
}
{
base.onMouseEnter (sender, e);
if (Selectable)
- IFace.MouseCursor = XCursor.Text;
+ IFace.MouseCursor = MouseCursor.IBeam;
}
public override void onMouseLeave (object sender, MouseMoveEventArgs e)
{
base.onMouseLeave (sender, e);
- IFace.MouseCursor = XCursor.Default;
+ IFace.MouseCursor = MouseCursor.Arrow;
}
protected override void onFocused (object sender, EventArgs e)
{
{
base.onMouseEnter (sender, e);
if ((Parent as GenericStack).Orientation == Orientation.Horizontal)
- IFace.MouseCursor = XCursor.H;
+ IFace.MouseCursor = MouseCursor.H;
else
- IFace.MouseCursor = XCursor.V;
+ IFace.MouseCursor = MouseCursor.V;
}
public override void onMouseLeave (object sender, MouseMoveEventArgs e)
{
base.onMouseLeave (sender, e);
- IFace.MouseCursor = XCursor.Default;
+ IFace.MouseCursor = MouseCursor.Arrow;
}
public override void onMouseDown (object sender, MouseButtonEventArgs e)
{
if (!hoverBorder) {
currentDirection = Direction.None;
- IFace.MouseCursor = XCursor.Default;
+ IFace.MouseCursor = MouseCursor.Arrow;
return;
}
if (currentDirection != lastDir) {
switch (currentDirection) {
case Direction.None:
- otkgw.MouseCursor = XCursor.Default;
+ otkgw.MouseCursor = MouseCursor.Move;
break;
case Direction.N:
- otkgw.MouseCursor = XCursor.V;
+ otkgw.MouseCursor = MouseCursor.Top;
break;
case Direction.S:
- otkgw.MouseCursor = XCursor.V;
+ otkgw.MouseCursor = MouseCursor.Bottom;
break;
case Direction.E:
- otkgw.MouseCursor = XCursor.H;
+ otkgw.MouseCursor = MouseCursor.Right;
break;
case Direction.W:
- otkgw.MouseCursor = XCursor.H;
+ otkgw.MouseCursor = MouseCursor.Left;
break;
case Direction.NW:
- otkgw.MouseCursor = XCursor.NW;
+ otkgw.MouseCursor = MouseCursor.TopLeft;
break;
case Direction.NE:
- otkgw.MouseCursor = XCursor.NE;
+ otkgw.MouseCursor = MouseCursor.TopRight;
break;
case Direction.SW:
- otkgw.MouseCursor = XCursor.SW;
+ otkgw.MouseCursor = MouseCursor.BottomLeft;
break;
case Direction.SE:
- otkgw.MouseCursor = XCursor.SE;
+ otkgw.MouseCursor = MouseCursor.BottomRight;
break;
}
}
{
hoverBorder = false;
currentDirection = Direction.None;
- IFace.MouseCursor = XCursor.Default;
+ IFace.MouseCursor = MouseCursor.Arrow;
}
protected virtual void onBorderMouseEnter (object sender, MouseMoveEventArgs e)
{
protected void butQuitPress (object sender, MouseButtonEventArgs e)
{
- IFace.MouseCursor = XCursor.Default;
+ IFace.MouseCursor = MouseCursor.Arrow;
close ();
}
{
while (running) {
Update ();
- Thread.Sleep (8);
+ Thread.Sleep (5);
}
}
if (!clipping.IsEmpty) {
IsDirty = true;
- for (int i = 0; i < clipping.NumRectangles; i++)
- ctx.Rectangle(clipping.GetRectangle(i));
-
- ctx.ClipPreserve();
- ctx.Operator = Operator.Clear;
- ctx.Fill();
- ctx.Operator = Operator.Over;
+ ctx.PushGroup ();
for (int i = GraphicTree.Count -1; i >= 0 ; i--){
Widget p = GraphicTree[i];
}
}
- #if DEBUG_CLIP_RECTANGLE
+#if DEBUG_CLIP_RECTANGLE
ctx.LineWidth = 1;
ctx.SetSourceColor(Color.Magenta.AdjustAlpha (0.5));
for (int i = 0; i < clipping.NumRectangles; i++)
ctx.Rectangle(clipping.GetRectangle(i));
ctx.Stroke ();
- #endif
+#endif
+
+ ctx.PopGroupToSource ();
+
+ for (int i = 0; i < clipping.NumRectangles; i++)
+ ctx.Rectangle (clipping.GetRectangle (i));
+
+ ctx.ClipPreserve ();
+ ctx.Operator = Operator.Clear;
+ ctx.Fill ();
+ ctx.Operator = Operator.Over;
+
+ ctx.Paint ();
clipping.Dispose ();
clipping = new Region ();
}
#region Mouse and Keyboard Handling
- XCursor cursor = XCursor.Default;
+ MouseCursor cursor = MouseCursor.Arrow;
public MouseState Mouse;
- public XCursor MouseCursor {
+ public MouseCursor MouseCursor {
set {
+
if (value == cursor)
return;
cursor = value;
- MouseCursorChanged.Raise (this,new MouseCursorChangedEventArgs(cursor));
+ if (backend != null)
+ backend.Cursor = cursor;
+ //MouseCursorChanged.Raise (this,new MouseCursorChangedEventArgs(cursor));
}
}
/// <summary>Processes mouse move events from the root container, this function
if (DragAndDropOperation != null)//drag source cant have hover event, so move has to be handle here
DragAndDropOperation.DragSource.onMouseMove (this, e);
- if (HoverWidget != null) {
+ if (_hoverWidget != null) {
resetTooltip ();
//check topmost graphicobject first
- Widget tmp = HoverWidget;
+ Widget tmp = _hoverWidget;
Widget topc = null;
while (tmp is Widget) {
topc = tmp;
while (i < idxhw) {
if (!GraphicTree [i].isPopup) {
if (GraphicTree [i].MouseIsIn (e.Position)) {
- while (HoverWidget != null) {
- HoverWidget.onMouseLeave (HoverWidget, e);
- HoverWidget = HoverWidget.focusParent;
+ while (_hoverWidget != null) {
+ _hoverWidget.onMouseLeave (_hoverWidget, e);
+ HoverWidget = _hoverWidget.focusParent;
}
GraphicTree [i].checkHoverWidget (e);
- HoverWidget.onMouseMove (this, e);
+ _hoverWidget.onMouseMove (this, e);
return true;
}
}
}
}
- if (HoverWidget.MouseIsIn (e.Position)) {
- HoverWidget.checkHoverWidget (e);
- HoverWidget.onMouseMove (this, e);
+ if (_hoverWidget.MouseIsIn (e.Position)) {
+ _hoverWidget.checkHoverWidget (e);
+ _hoverWidget.onMouseMove (this, e);
return true;
- } else {
- HoverWidget.onMouseLeave (HoverWidget, e);
- //seek upward from last focused graph obj's
- while (HoverWidget.focusParent != null) {
- HoverWidget = HoverWidget.focusParent;
- if (HoverWidget.MouseIsIn (e.Position)) {
- HoverWidget.checkHoverWidget (e);
- HoverWidget.onMouseMove (this, e);
- return true;
- } else
- HoverWidget.onMouseLeave (HoverWidget, e);
+ }
+ _hoverWidget.onMouseLeave (_hoverWidget, e);
+ //seek upward from last focused graph obj's
+ while (_hoverWidget.focusParent != null) {
+ HoverWidget = _hoverWidget.focusParent;
+ if (_hoverWidget.MouseIsIn (e.Position)) {
+ _hoverWidget.checkHoverWidget (e);
+ _hoverWidget.onMouseMove (this, e);
+ return true;
}
- }
+ _hoverWidget.onMouseLeave (_hoverWidget, e);
+ }
}
//top level graphic obj's parsing
g.checkHoverWidget (e);
if (g is Window)
PutOnTop (g);
- HoverWidget.onMouseMove (this, e);
+ _hoverWidget.onMouseMove (this, e);
return true;
}
}
Mouse.EnableBit ((int)button);
MouseButtonEventArgs e = new MouseButtonEventArgs (button) { Mouse = Mouse };
- if (HoverWidget == null)
+ if (_hoverWidget == null)
return false;
- Widget hoverFocused = HoverWidget;
+ Widget hoverFocused = _hoverWidget;
while (!hoverFocused.Focusable) {
hoverFocused = hoverFocused.focusParent;
if (hoverFocused == null) {
- hoverFocused = HoverWidget;
+ hoverFocused = _hoverWidget;
break;
}
}
armedClickSender.onMouseClick (armedClickSender, armedClickEvtArgs);
armedClickSender = null;
- HoverWidget.onMouseDown(HoverWidget,new BubblingMouseButtonEventArg(e));
+ _hoverWidget.onMouseDown(_hoverWidget,new BubblingMouseButtonEventArg(e));
- if (FocusedWidget == null)
+ if (_focusedWidget == null)
return true;
ActiveWidget = FocusedWidget;
Mouse.SetScrollRelative (0, delta);
MouseWheelEventArgs e = new MouseWheelEventArgs () { Mouse = Mouse, DeltaPrecise = delta };
- if (HoverWidget == null)
+ if (_hoverWidget == null)
return false;
- HoverWidget.onMouseWheel (this, e);
+ _hoverWidget.onMouseWheel (this, e);
return true;
}
#region Tooltip handling
Stopwatch tooltipTimer = new Stopwatch();
- Widget ToolTipContainer = null;
- volatile bool tooltipVisible = false;
+ Widget ToolTipContainer;
+ volatile bool tooltipVisible;
protected void initTooltip () {
ToolTipContainer = CreateInstance ("#Crow.Tooltip.template");
ctxMenuContainer.Left = Mouse.X - 5;
ctxMenuContainer.Top = Mouse.Y - 5;
- HoverWidget = ctxMenuContainer;
+ _hoverWidget = ctxMenuContainer;
ctxMenuContainer.onMouseEnter (ctxMenuContainer, new MouseMoveEventArgs (Mouse.X, Mouse.Y, 0, 0));
}
#endregion
{
public class MouseCursorChangedEventArgs : EventArgs
{
- public XCursor NewCursor;
- public MouseCursorChangedEventArgs (XCursor newCursor) : base()
+ public MouseCursor NewCursor;
+ public MouseCursorChangedEventArgs (MouseCursor newCursor) : base()
{
NewCursor = newCursor;
}
void Flush();
void ProcessEvents();
+ MouseCursor Cursor { set; }
bool IsDown (Key key);
bool Shift { get; }
bool Ctrl { get; }
WindowProcedureDelegate = WindowProcedure;
- Rect rect = new Rect
- {
+ Rect rect = new Rect {
Left = iFace.ClientRectangle.Left,
Top = iFace.ClientRectangle.Top,
Right = iFace.ClientRectangle.Right,
User32.Window.AdjustWindowRectEx (ref rect, 0, false, 0);
- ExtendedWindowClass wc = new ExtendedWindowClass
- {
+ ExtendedWindowClass wc = new ExtendedWindowClass {
Size = ExtendedWindowClass.SizeInBytes,
Style = 0,
WindowProc = WindowProcedureDelegate,
}
}
+ public MouseCursor Cursor { set { throw new NotImplementedException(); } }
+
public bool IsDown (Key key) {
return false;
}
--- /dev/null
+//
+// XCursor.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+// Copyright (c) 2013-2017 Jean-Philippe Bruyère
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using System.IO;
+using System.Diagnostics;
+using System.Collections.Generic;
+
+namespace Crow
+{
+ public class XCursorFile
+ {
+ const uint XC_TYPE_IMG = 0xfffd0002;
+
+ class toc
+ {
+ public uint type;
+ public uint subtype;
+ public uint pos;
+
+ public toc(BinaryReader sr)
+ {
+ type = sr.ReadUInt32();
+ subtype = sr.ReadUInt32();
+ pos = sr.ReadUInt32();
+ }
+ }
+
+ public List<XCursor> Cursors = new List<XCursor>();
+
+
+ static XCursorFile loadFromStream(Stream s)
+ {
+ List<toc> tocList = new List<toc> ();
+ XCursorFile tmp = new XCursorFile ();
+
+ using (BinaryReader sr = new BinaryReader (s)) {
+ byte[] data;
+ //magic: CARD32 ’Xcur’ (0x58, 0x63, 0x75, 0x72)
+ if (new string (sr.ReadChars (4)) != "Xcur") {
+ Debug.WriteLine ("XCursor Load error: Wrong magic");
+ return null;
+ }
+ //header: CARD32 bytes in this header
+ uint headerLength = sr.ReadUInt32 ();
+ //version: CARD32 file version number
+ uint version = sr.ReadUInt32 ();
+ //ntoc: CARD32 number of toc entries
+ uint nbToc = sr.ReadUInt32 ();
+ //toc: LISTofTOC table of contents
+ for (uint i = 0; i < nbToc; i++) {
+ tocList.Add (new toc (sr));
+ }
+
+ foreach (toc t in tocList) {
+ if (t.type != XC_TYPE_IMG)
+ continue;
+
+ sr.BaseStream.Seek (t.pos, SeekOrigin.Begin);
+ tmp.Cursors.Add(imageLoad (sr));
+ }
+ }
+ return tmp;
+ }
+
+ public static XCursorFile Load(Interface iface, string path)
+ {
+ return loadFromStream (iface.GetStreamFromPath (path));
+ }
+
+ static XCursor imageLoad (BinaryReader sr)
+ {
+ XCursor tmp = new XCursor ();
+ // header: 36 Image headers are 36 bytes
+ uint header = sr.ReadUInt32();
+ // type: 0xfffd0002 Image type is 0xfffd0002
+ uint type = sr.ReadUInt32();
+ // subtype: CARD32 Image subtype is the nominal size
+ uint subtype = sr.ReadUInt32();
+ // version: 1
+ uint version = sr.ReadUInt32();
+ // width: CARD32 Must be less than or equal to 0x7fff
+ tmp.Width = sr.ReadUInt32();
+ // height: CARD32 Must be less than or equal to 0x7fff
+ tmp.Height = sr.ReadUInt32();
+ // xhot: CARD32 Must be less than or equal to width
+ tmp.Xhot = sr.ReadUInt32();
+ // yhot: CARD32 Must be less than or equal to height
+ tmp.Yhot = sr.ReadUInt32();
+ // delay: CARD32 Delay between animation frames in milliseconds
+ tmp.Delay = sr.ReadUInt32();
+ // pixels: LISTofCARD32 Packed ARGB format pixels
+ tmp.data = sr.ReadBytes((int)(tmp.Width * tmp.Height * 4));
+ return tmp;
+ }
+ }
+ public class XCursor
+ {
+ public static XCursor Default;
+ public static XCursor Cross;
+ public static XCursor Arrow;
+ public static XCursor Text;
+ public static XCursor SW;
+ public static XCursor SE;
+ public static XCursor NW;
+ public static XCursor NE;
+ public static XCursor N;
+ public static XCursor S;
+ public static XCursor V;
+ public static XCursor H;
+
+ public uint Width;
+ public uint Height;
+ public uint Xhot;
+ public uint Yhot;
+ public uint Delay;
+ public byte[] data;
+
+ public XCursor ()
+ {
+ }
+// public static implicit operator XCursor(XCursor xc)
+// {
+// return new XCursor((int)xc.Xhot, (int)xc.Yhot, (int)xc.Width, (int)xc.Height,xc.data);
+// }
+ }
+}
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
-using System.Diagnostics;
+using System.Collections.Generic;
using System.Runtime.InteropServices;
-using System.Text;
namespace Crow.XCB
-{
+{
using xcb_window_t = System.UInt32;
- using xcb_pixmap_t = System.UInt32;
- using xcb_cursor_t = System.UInt32;
- using xcb_font_t = System.UInt32;
using xcb_colormap_t = System.UInt32;
- using xcb_atom_t = System.UInt32;
- using xcb_drawable_t = System.UInt32;
using xcb_visualid_t = System.UInt32;
- using xcb_keysym_t = System.UInt32;
using xcb_keycode_t = System.Byte;
using xcb_timestamp_t = System.UInt32;
MAPPING_NOTIFY,
GE_GENERIC,
}
+
[Flags]
enum xcb_cw_t : uint {
BACK_PIXMAP = 1,
#region pinvoke XCB
- [DllImportAttribute ("xcb")]
+ [DllImport ("xcb")]
static extern IntPtr xcb_connect(string displayName, IntPtr screenNum);
- [DllImportAttribute("xcb")]
+ [DllImport ("xcb")]
static extern IntPtr xcb_get_setup(IntPtr connection);
- [DllImportAttribute("xcb")]
+ [DllImport ("xcb")]
static extern IntPtr xcb_flush(IntPtr connection);
- [DllImportAttribute("xcb")]
+ [DllImport ("xcb")]
static extern UInt32 xcb_generate_id(IntPtr connection);
- [DllImportAttribute("xcb")]
+ [DllImport("xcb")]
static extern xcb_iterator_t xcb_setup_roots_iterator(IntPtr setup);
- [DllImportAttribute("xcb")]
+ [DllImport("xcb")]
static extern xcb_iterator_t xcb_screen_allowed_depths_iterator(IntPtr scr);
- [DllImportAttribute("xcb")]
+ [DllImport("xcb")]
static extern xcb_iterator_t xcb_depth_visuals_iterator(IntPtr depth);
- [DllImportAttribute("xcb")]
+ [DllImport("xcb")]
static extern void xcb_screen_next(ref xcb_iterator_t scr_iterator);
- [DllImportAttribute("xcb")]
+ [DllImport("xcb")]
static extern void xcb_depth_next(ref xcb_iterator_t depth_iterator);
- [DllImportAttribute("xcb")]
+ [DllImport("xcb")]
static extern void xcb_visualtype_next(ref xcb_iterator_t depth_visual_iterator);
- [DllImportAttribute("xcb")]
+ [DllImport("xcb")]
static extern xcb_void_cookie_t xcb_create_window(IntPtr connection, byte depth, xcb_window_t win, UInt32 parent,
Int16 x, Int16 y, UInt16 width, UInt16 height, UInt16 border,
xcb_window_class_t _class, xcb_visualid_t visual, xcb_cw_t mask, IntPtr valueList);
- [DllImportAttribute("xcb")]
+ [DllImport("xcb")]
static extern xcb_void_cookie_t xcb_map_window(IntPtr conn, xcb_window_t window);
- [DllImportAttribute("xcb")]
+ [DllImport("xcb")]
static extern void xcb_disconnect(IntPtr connection);
- [DllImportAttribute("xcb")]
+ [DllImport("xcb")]
static extern IntPtr xcb_poll_for_event(IntPtr connection);
+ [DllImport ("xcb")]
+ static extern xcb_void_cookie_t xcb_change_window_attributes (IntPtr conn, xcb_window_t window, xcb_cw_t value_mask, IntPtr value_list);
+
+ [DllImport ("xcb")]//in xcbproto
+ static extern xcb_void_cookie_t xcb_free_cursor (IntPtr connection, UInt32 cursor);
+
+ //TODO: there should be a generic free method in xcb or at least xcb_free_event!!
+ [DllImport ("X11")]
+ static extern IntPtr XFree (IntPtr data);
+ //[DllImport ("X11")]
+ //static extern int XInitThreads ();
+ //[DllImport ("X11")]
+ //static extern void XLockDisplay (IntPtr display);
+ //[DllImport ("X11")]
+ //static extern void XUnlockDisplay (IntPtr display);
+
+ #region xcb_cursor
+ [DllImport ("xcb-cursor")]
+ static extern int xcb_cursor_context_new (IntPtr conn, IntPtr screen, out IntPtr ctx);
+ [DllImport ("xcb-cursor", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
+ static extern UInt32 xcb_cursor_load_cursor (IntPtr ctx, [MarshalAs (UnmanagedType.LPStr)]string name);
+ [DllImport ("xcb-cursor")]
+ static extern void xcb_cursor_context_free (IntPtr ctx);
+
+ #endregion
#endregion
Interface iFace;
IntPtr conn;
+ xcb_window_t win;
+
+ IntPtr cursorCtx;
+ Dictionary<MouseCursor, xcb_window_t> cursors;
XKB.XCBKeyboard Keyboard;
conn = xcb_connect (null, IntPtr.Zero);
-
Keyboard = new XKB.XCBKeyboard (conn, iFace);
xcb_iterator_t scr_it = xcb_setup_roots_iterator (xcb_get_setup (conn));
xcb_screen_t scr = (xcb_screen_t)Marshal.PtrToStructure (screen, typeof(xcb_screen_t));
- xcb_window_t win = xcb_generate_id (conn);
+ win = xcb_generate_id (conn);
xcb_cw_t mask = xcb_cw_t.BACK_PIXEL | xcb_cw_t.EVENT_MASK;
uint[] values = {
)
};
- IntPtr intPtr = IntPtr.Zero;
- unsafe
- {
- fixed(uint* pValues = values)
- intPtr = new IntPtr((void *) pValues);
- xcb_create_window (conn, XCB_COPY_FROM_PARENT, win, scr.root, 0,0,(ushort)iFace.ClientRectangle.Width, (ushort)iFace.ClientRectangle.Height,0,
- xcb_window_class_t.INPUT_OUTPUT, scr.root_visual, mask, intPtr);
- }
+ GCHandle hndValues = GCHandle.Alloc (values, GCHandleType.Pinned);
+
+ xcb_create_window (conn, XCB_COPY_FROM_PARENT, win, scr.root, 0,0,(ushort)iFace.ClientRectangle.Width, (ushort)iFace.ClientRectangle.Height,0,
+ xcb_window_class_t.INPUT_OUTPUT, scr.root_visual, mask, hndValues.AddrOfPinnedObject());
+
+ hndValues.Free ();
xcb_map_window (conn, win);
IntPtr visual = findVisual (scr_it, scr.root_visual);
- //loadCursors ();
+ if (xcb_cursor_context_new (conn, screen, out cursorCtx) < 0)
+ throw new Exception ("Could not initialize xcb-cursor");
+
+ loadCursors ();
iFace.surf = new Cairo.XcbSurface (conn, win, visual, iFace.ClientRectangle.Width, iFace.ClientRectangle.Height);
}
{
Keyboard.Destroy ();
+ foreach (xcb_window_t cur in cursors.Values)
+ xcb_free_cursor (conn, cur);
+
+ xcb_cursor_context_free (cursorCtx);
+
xcb_disconnect (conn);
}
public void Flush () {
Console.WriteLine ("unknown event");
break;
}
+ XFree (evtPtr);
}
public bool IsDown (Key key) {
return false;
public bool Alt {
get { return Keyboard.Alt;}
}
+
+ public MouseCursor Cursor {
+ set {
+ GCHandle hndValues = GCHandle.Alloc (cursors [value], GCHandleType.Pinned);
+ xcb_void_cookie_t res = xcb_change_window_attributes (conn, win, xcb_cw_t.CURSOR, hndValues.AddrOfPinnedObject ());
+ hndValues.Free ();
+ xcb_flush (conn);
+ }
+ }
#endregion
+ UInt32 tryGetCursor (params string[] names)
+ {
+ for (int i = 0; i < names.Length; i++) {
+ xcb_window_t cur = xcb_cursor_load_cursor (cursorCtx, names[i]);
+ if (cur != 0)
+ return cur;
+ }
+ return 0;
+ }
+
+
void loadCursors ()
{
+ cursors = new Dictionary<MouseCursor, xcb_window_t> ();
//Load cursors
- XCursor.Cross = XCursorFile.Load (iFace, "#Crow.Images.Icons.Cursors.cross").Cursors [0];
- XCursor.Default = XCursorFile.Load (iFace, "#Crow.Images.Icons.Cursors.arrow").Cursors [0];
- XCursor.NW = XCursorFile.Load (iFace, "#Crow.Images.Icons.Cursors.top_left_corner").Cursors [0];
- XCursor.NE = XCursorFile.Load (iFace, "#Crow.Images.Icons.Cursors.top_right_corner").Cursors [0];
- XCursor.SW = XCursorFile.Load (iFace, "#Crow.Images.Icons.Cursors.bottom_left_corner").Cursors [0];
- XCursor.SE = XCursorFile.Load (iFace, "#Crow.Images.Icons.Cursors.bottom_right_corner").Cursors [0];
- XCursor.H = XCursorFile.Load (iFace, "#Crow.Images.Icons.Cursors.sb_h_double_arrow").Cursors [0];
- XCursor.V = XCursorFile.Load (iFace, "#Crow.Images.Icons.Cursors.sb_v_double_arrow").Cursors [0];
- XCursor.Text = XCursorFile.Load (iFace, "#Crow.Images.Icons.Cursors.ibeam").Cursors [0];
+ cursors.Add (MouseCursor.Arrow, tryGetCursor("arrow", "default"));
+ cursors.Add (MouseCursor.IBeam, tryGetCursor ("text", "ibeam"));
+ cursors.Add (MouseCursor.Crosshair, tryGetCursor ("cross", "crosshair"));
+ cursors.Add (MouseCursor.Hand, tryGetCursor ("hand", "hand2", "hand1", "pointing_hand"));
+ cursors.Add (MouseCursor.Move, tryGetCursor ("move"));
+ cursors.Add (MouseCursor.Circle, tryGetCursor ("circle"));
+ cursors.Add (MouseCursor.H, tryGetCursor ("ew-resize"));
+ cursors.Add (MouseCursor.V, tryGetCursor ("ns-resize"));
+ cursors.Add (MouseCursor.NW, tryGetCursor ("nw-resize"));
+ cursors.Add (MouseCursor.NE, tryGetCursor ("ne-resize"));
+ cursors.Add (MouseCursor.SW, tryGetCursor ("sw-resize"));
+ cursors.Add (MouseCursor.SE, tryGetCursor ("se-resize"));
+ cursors.Add (MouseCursor.TopLeft, tryGetCursor ("nw-resize"));
+ cursors.Add (MouseCursor.Top, tryGetCursor ("n-resize"));
+ cursors.Add (MouseCursor.TopRight, tryGetCursor ("ne-resize"));
+ cursors.Add (MouseCursor.Left, tryGetCursor ("w-resize"));
+ cursors.Add (MouseCursor.Right, tryGetCursor ("e-resize"));
+ cursors.Add (MouseCursor.BottomLeft, tryGetCursor ("sw-resize"));
+ cursors.Add (MouseCursor.Bottom, tryGetCursor ("s-resize"));
+ cursors.Add (MouseCursor.BottomRight, tryGetCursor ("se-resize"));
}
static IntPtr findVisual (xcb_iterator_t scr_it, xcb_visualid_t visualId){
+++ /dev/null
-//
-// XCursor.cs
-//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-using System;
-using System.IO;
-using System.Diagnostics;
-using System.Collections.Generic;
-
-namespace Crow
-{
- public class XCursorFile
- {
- const uint XC_TYPE_IMG = 0xfffd0002;
-
- class toc
- {
- public uint type;
- public uint subtype;
- public uint pos;
-
- public toc(BinaryReader sr)
- {
- type = sr.ReadUInt32();
- subtype = sr.ReadUInt32();
- pos = sr.ReadUInt32();
- }
- }
-
- public List<XCursor> Cursors = new List<XCursor>();
-
-
- static XCursorFile loadFromStream(Stream s)
- {
- List<toc> tocList = new List<toc> ();
- XCursorFile tmp = new XCursorFile ();
-
- using (BinaryReader sr = new BinaryReader (s)) {
- byte[] data;
- //magic: CARD32 ’Xcur’ (0x58, 0x63, 0x75, 0x72)
- if (new string (sr.ReadChars (4)) != "Xcur") {
- Debug.WriteLine ("XCursor Load error: Wrong magic");
- return null;
- }
- //header: CARD32 bytes in this header
- uint headerLength = sr.ReadUInt32 ();
- //version: CARD32 file version number
- uint version = sr.ReadUInt32 ();
- //ntoc: CARD32 number of toc entries
- uint nbToc = sr.ReadUInt32 ();
- //toc: LISTofTOC table of contents
- for (uint i = 0; i < nbToc; i++) {
- tocList.Add (new toc (sr));
- }
-
- foreach (toc t in tocList) {
- if (t.type != XC_TYPE_IMG)
- continue;
-
- sr.BaseStream.Seek (t.pos, SeekOrigin.Begin);
- tmp.Cursors.Add(imageLoad (sr));
- }
- }
- return tmp;
- }
-
- public static XCursorFile Load(Interface iface, string path)
- {
- return loadFromStream (iface.GetStreamFromPath (path));
- }
-
- static XCursor imageLoad(BinaryReader sr)
- {
- XCursor tmp = new XCursor();
- // header: 36 Image headers are 36 bytes
- uint header = sr.ReadUInt32();
- // type: 0xfffd0002 Image type is 0xfffd0002
- uint type = sr.ReadUInt32();
- // subtype: CARD32 Image subtype is the nominal size
- uint subtype = sr.ReadUInt32();
- // version: 1
- uint version = sr.ReadUInt32();
- // width: CARD32 Must be less than or equal to 0x7fff
- tmp.Width = sr.ReadUInt32();
- // height: CARD32 Must be less than or equal to 0x7fff
- tmp.Height = sr.ReadUInt32();
- // xhot: CARD32 Must be less than or equal to width
- tmp.Xhot = sr.ReadUInt32();
- // yhot: CARD32 Must be less than or equal to height
- tmp.Yhot = sr.ReadUInt32();
- // delay: CARD32 Delay between animation frames in milliseconds
- tmp.Delay = sr.ReadUInt32();
- // pixels: LISTofCARD32 Packed ARGB format pixels
- tmp.data = sr.ReadBytes((int)(tmp.Width * tmp.Height * 4));
- return tmp;
- }
- }
- public class XCursor
- {
- public static XCursor Default;
- public static XCursor Cross;
- public static XCursor Arrow;
- public static XCursor Text;
- public static XCursor SW;
- public static XCursor SE;
- public static XCursor NW;
- public static XCursor NE;
- public static XCursor N;
- public static XCursor S;
- public static XCursor V;
- public static XCursor H;
-
- public uint Width;
- public uint Height;
- public uint Xhot;
- public uint Yhot;
- public uint Delay;
- public byte[] data;
-
- public XCursor ()
- {
- }
-// public static implicit operator MouseCursor(XCursor xc)
-// {
-// return new MouseCursor((int)xc.Xhot, (int)xc.Yhot, (int)xc.Width, (int)xc.Height,xc.data);
-// }
- }
-}
-
// NOT COMPLETE
using System;
-using System.ComponentModel;
-using System.Collections;
-using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
-using System.Reflection;
// X11 Version
-namespace Crow.XLib {
+namespace Crow.XLib
+{
//
// In the structures below, fields of type long are mapped to IntPtr.
// This will work on all platforms where sizeof(long)==sizeof(void*), which
public class XLibBackend : IBackend
{
#region pinvoke
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern int XInitThreads();
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
internal static extern IntPtr XOpenDisplay(IntPtr displayName);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
internal static extern IntPtr XCloseDisplay(IntPtr disp);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern Int32 XDefaultScreen(IntPtr disp);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern IntPtr XDefaultRootWindow(IntPtr disp);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern UInt32 XDefaultDepth (IntPtr disp, Int32 screen);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern IntPtr XDefaultVisual(IntPtr disp, Int32 screen);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern IntPtr XCreateSimpleWindow(IntPtr disp, IntPtr rootWindow, Int32 x, Int32 y, UInt32 width, UInt32 height,
UInt32 borderWidth, IntPtr border, IntPtr background);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern IntPtr XCreatePixmap(IntPtr disp, IntPtr rootWindow, UInt32 width, UInt32 height, UInt32 depth);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern IntPtr XFreePixmap(IntPtr disp, IntPtr pixmap);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern IntPtr XFree(IntPtr data);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern Int32 XSelectInput(IntPtr disp, IntPtr win, EventMask eventMask);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern Int32 XMapWindow(IntPtr disp, IntPtr win);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern int XPending (IntPtr disp);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern IntPtr XNextEvent(IntPtr disp, ref XEvent xevent);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern Int32 XSync(IntPtr disp, int discard);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern int XConnectionNumber(IntPtr disp);
- [DllImportAttribute("X11")]
+ [DllImport("X11")]
static extern IntPtr XSetErrorHandler(XErrorHandler error_handler);
#endregion
throw new NotImplementedException ();
}
}
+ public MouseCursor Cursor { set { throw new NotImplementedException (); } }
#endregion
int HandleError (IntPtr display, ref XErrorEvent error_event)