]> O.S.I.I.S - jp/crow.git/commitdiff
xcb cursor, cairo push/pop group to get rid of flickering in xcb
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 6 Aug 2019 08:16:09 +0000 (10:16 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 6 Aug 2019 08:16:09 +0000 (10:16 +0200)
15 files changed:
Crow/Default.style
Crow/Templates/MenuItem.template
Crow/src/Enums.cs
Crow/src/GraphicObjects/Label.cs
Crow/src/GraphicObjects/Splitter.cs
Crow/src/GraphicObjects/Window.cs
Crow/src/Interface.cs
Crow/src/MouseCursorChangedEventArgs.cs
Crow/src/backends/IBackend.cs
Crow/src/backends/win32/WinBackend.cs
Crow/src/backends/xcb/MouseCursor.cs [new file with mode: 0644]
Crow/src/backends/xcb/XCBBackend.cs
Crow/src/backends/xcb/XCursor.cs [deleted file]
Crow/src/backends/xlib/X11Structs.cs
Crow/src/backends/xlib/XLibBackend.cs

index 5343c09f583bc3b4eebcf97caf5022962f1ac2b9..1e017ce6fbed01d445c4dc86c88fb2a86029562b 100644 (file)
@@ -56,8 +56,8 @@ MenuItem {
        //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";
index d33216615f466a8a01ed8609afc8dc96c0ab49df..f6f9a9ac9ef781133bb9709b645f378fc9f498c1 100644 (file)
@@ -1,5 +1,4 @@
 <?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}">
@@ -21,6 +20,4 @@
        <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
index 8b90d6ea54da15caacc5f28cdd75468163628b82..42adab57e8676c342f7547ee0440b8961ca323b9 100644 (file)
@@ -62,4 +62,28 @@ namespace Crow
         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,
+       }
 }
index c7bd5124fb586168aa5325604d7b944248468d6d..265afcb3e04d778ef89dcc4e4d6c2af5eba3cc70 100644 (file)
@@ -689,12 +689,12 @@ namespace Crow
                {
                        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)
                {
index e1f8e637739ac3f509f778278dffa86ba950fbd2..5b400e8063891ed233f17e8cc08a3f5794872d2a 100644 (file)
@@ -91,14 +91,14 @@ namespace Crow
                {
                        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)
                {
index 6c8f005e0d770c59e9c4e0df4d01e7bfca951f68..a9effb8886e2696c8d6c9597d56bb1218b46ef3c 100644 (file)
@@ -296,7 +296,7 @@ namespace Crow
 
                        if (!hoverBorder) {
                                currentDirection = Direction.None;
-                               IFace.MouseCursor = XCursor.Default;
+                               IFace.MouseCursor = MouseCursor.Arrow;
                                return;
                        }
 
@@ -333,31 +333,31 @@ namespace Crow
                                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;
                                        }
                                }                               
@@ -423,7 +423,7 @@ namespace Crow
                {
                        hoverBorder = false;
                        currentDirection = Direction.None;
-                       IFace.MouseCursor = XCursor.Default;
+                       IFace.MouseCursor = MouseCursor.Arrow;
                }
                protected virtual void onBorderMouseEnter (object sender, MouseMoveEventArgs e)
                {
@@ -433,7 +433,7 @@ namespace Crow
 
                protected void butQuitPress (object sender, MouseButtonEventArgs e)
                {
-                       IFace.MouseCursor = XCursor.Default;
+                       IFace.MouseCursor = MouseCursor.Arrow;
                        close ();
                }
 
index d4376a4dc20e641fe379725e414ce6dc80f93e8b..b18d1f734ba4fc3b0f564ebb981030b2c5135fb6 100644 (file)
@@ -185,7 +185,7 @@ namespace Crow
                {                       
                        while (running) {
                                Update ();
-                               Thread.Sleep (8);
+                               Thread.Sleep (5);
                        }
                }
 
@@ -804,13 +804,7 @@ namespace Crow
                                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];
@@ -840,13 +834,25 @@ namespace Crow
                                                }
                                        }
 
-                                       #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 ();
@@ -999,16 +1005,19 @@ namespace Crow
                }
 
                #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
@@ -1037,10 +1046,10 @@ namespace Crow
                        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;
@@ -1052,13 +1061,13 @@ namespace Crow
                                        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;
                                                        }
                                                }
@@ -1066,23 +1075,22 @@ namespace Crow
                                        }
                                }
 
-                               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
@@ -1093,7 +1101,7 @@ namespace Crow
                                                g.checkHoverWidget (e);
                                                if (g is Window)
                                                        PutOnTop (g);
-                                               HoverWidget.onMouseMove (this, e);
+                                               _hoverWidget.onMouseMove (this, e);
                                                return true;
                                        }
                                }
@@ -1141,14 +1149,14 @@ namespace Crow
                        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;
                                }
                        }
@@ -1164,9 +1172,9 @@ namespace Crow
                                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;
@@ -1187,9 +1195,9 @@ namespace Crow
                        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;
                }
 
@@ -1200,8 +1208,8 @@ namespace Crow
 
                #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");
@@ -1279,7 +1287,7 @@ namespace Crow
                        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
index 9c63c11fb4daa72a8dda528c87b3095ed8d1d559..5e58b861ef96e44d7cccdafedc8b2fc6e2dae08b 100644 (file)
@@ -30,8 +30,8 @@ namespace Crow
 {
        public class MouseCursorChangedEventArgs : EventArgs
        {
-               public XCursor NewCursor;
-               public MouseCursorChangedEventArgs (XCursor newCursor) : base()
+               public MouseCursor NewCursor;
+               public MouseCursorChangedEventArgs (MouseCursor newCursor) : base()
                {
                        NewCursor = newCursor;
                }
index 3275205e17f180942fec57b5ef6e8641815e25e1..0cad0f4fb77b8dfdae414924b15a3dbe6f7ba422 100644 (file)
@@ -34,6 +34,7 @@ namespace Crow
                void Flush();
                void ProcessEvents();
 
+               MouseCursor Cursor { set; }
                bool IsDown (Key key);
                bool Shift { get; }
                bool Ctrl { get; }
index 0b3f873c0f0dd4809d1e9bf48069a924f93e10d0..50e54b93582783d89554a94a5c37a89e8b85e7c5 100755 (executable)
@@ -54,8 +54,7 @@ namespace Crow.Win32 {
 
                        WindowProcedureDelegate = WindowProcedure;
 
-                       Rect rect = new Rect
-                       {
+                       Rect rect = new Rect {
                                Left = iFace.ClientRectangle.Left,
                                Top = iFace.ClientRectangle.Top,
                                Right = iFace.ClientRectangle.Right,
@@ -64,8 +63,7 @@ namespace Crow.Win32 {
 
                        User32.Window.AdjustWindowRectEx (ref rect, 0, false, 0);
 
-                       ExtendedWindowClass wc = new ExtendedWindowClass
-                       {
+                       ExtendedWindowClass wc = new ExtendedWindowClass {
                                Size = ExtendedWindowClass.SizeInBytes,
                                Style = 0,
                                WindowProc = WindowProcedureDelegate,
@@ -112,6 +110,8 @@ namespace Crow.Win32 {
                        }
                }
 
+               public MouseCursor Cursor { set { throw new NotImplementedException(); } }
+
                public bool IsDown (Key key) {
                        return false;
                }
diff --git a/Crow/src/backends/xcb/MouseCursor.cs b/Crow/src/backends/xcb/MouseCursor.cs
new file mode 100644 (file)
index 0000000..8d29f67
--- /dev/null
@@ -0,0 +1,151 @@
+//
+// 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);
+//             }
+       }
+}
+
index 59376a8e32c774da35c95260245c4022abfabc8f..8464defb6edb9e56a7e21141cb39b9add47c5bfb 100644 (file)
 // 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;
 
@@ -137,6 +130,7 @@ namespace Crow.XCB
                        MAPPING_NOTIFY,
                        GE_GENERIC,
                }
+
                [Flags]
                enum xcb_cw_t : uint {
                        BACK_PIXMAP = 1,
@@ -324,47 +318,76 @@ namespace Crow.XCB
 
 
                #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;
 
@@ -376,7 +399,6 @@ namespace Crow.XCB
 
                        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));
@@ -384,7 +406,7 @@ namespace Crow.XCB
 
                        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 = {
@@ -399,15 +421,13 @@ namespace Crow.XCB
                                )
                        };
 
-                       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);
 
@@ -415,7 +435,10 @@ namespace Crow.XCB
 
                        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);
                }
@@ -424,6 +447,11 @@ namespace Crow.XCB
                {
                        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 () {
@@ -468,6 +496,7 @@ namespace Crow.XCB
                                Console.WriteLine ("unknown event");
                                break;
                        }
+                       XFree (evtPtr);
                }
                public bool IsDown (Key key) {
                        return false;
@@ -481,20 +510,52 @@ namespace Crow.XCB
                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){
diff --git a/Crow/src/backends/xcb/XCursor.cs b/Crow/src/backends/xcb/XCursor.cs
deleted file mode 100644 (file)
index 1cca510..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-//
-// 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);
-//             }
-       }
-}
-
index 5e43e006cae1744dfae7002c7ca7dcb0f9900669..79b2618002538ca7105e532a59c2a118b95b1390 100644 (file)
 // 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
index 111296e3f4a002c2f8f99a559c28a5ca2df95969..a8d62e06c31a2756d24c2d2d907d38b82105791c 100644 (file)
@@ -32,42 +32,42 @@ namespace Crow.XLib
        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
@@ -181,6 +181,7 @@ namespace Crow.XLib
                                throw new NotImplementedException ();
                        }
                }
+               public MouseCursor Cursor { set { throw new NotImplementedException (); } }
                #endregion
 
                int HandleError (IntPtr display, ref XErrorEvent error_event)