示例#1
0
        private static unsafe void MarkRectange(int x, int y, int width, int height)
        {
            var DamageRect = (Rect *)Libc.malloc(sizeof(Rect));

            DamageRect->X      = x;
            DamageRect->Y      = y;
            DamageRect->Width  = width;
            DamageRect->Height = height;

            Monitor.AcquireLock(ref RedrawRectsLock);
            RedrawRects.Enqueue((uint)DamageRect);
            Monitor.ReleaseLock(ref RedrawRectsLock);
        }
示例#2
0
        private static unsafe void HandleNewWindow(GuiRequest *aRequest)
        {
            var WindowRequest = (NewWindow *)aRequest;

            int x      = WindowRequest->X;
            int y      = WindowRequest->Y;
            int width  = WindowRequest->Width;
            int height = WindowRequest->Height;

            if (width <= 0 || height <= 0)
            {
                aRequest->Error = ErrorType.BadParameters;
            }

            if (aRequest->Error != ErrorType.None)
            {
                ReplyClient(aRequest);
                return;
            }

            var window = new Window(aRequest->ClientID, x, y, width, height);

            Marshal.Copy(window.HashID, WindowRequest->Buffer, window.HashID.Length);

            Monitor.AcquireLock(ref WindowsLock);

            int id = Windows.Count;

            window.ID = id;
            WindowRequest->WindowID = id;
            Windows.Add(window);

            Monitor.ReleaseLock(ref WindowsLock);
            ActiveWindow = window;

            Monitor.AcquireLock(ref StackingLock);
            Stacking.Add(window);
            Monitor.ReleaseLock(ref StackingLock);

            ReplyClient(aRequest);
        }
示例#3
0
        private static unsafe void Renderer()
        {
            int tmp_mouse_X, tmp_mouse_Y;
            int old_mouse_X = -1, old_mouse_Y = -1;

            bool update;

            while (true)
            {
                tmp_mouse_X = Mouse_X;
                tmp_mouse_Y = Mouse_Y;
                update      = false;

                Cairo.Save(MainContext);
                Cairo.Save(VideoContext);

                if (tmp_mouse_X != old_mouse_X || tmp_mouse_Y != old_mouse_Y)
                {
                    update = true;
                    Cairo.Rectangle(32, 32, old_mouse_Y, old_mouse_X, MainContext);
                    Cairo.Rectangle(32, 32, old_mouse_Y, old_mouse_X, VideoContext);
                    Cairo.Rectangle(32, 32, tmp_mouse_Y, tmp_mouse_X, VideoContext);
                }

                old_mouse_X = tmp_mouse_X;
                old_mouse_Y = tmp_mouse_Y;

                var queue = RedrawRects;
                Monitor.AcquireLock(ref RedrawRectsLock);
                while (queue.Count > 0)
                {
                    var rect = (Rect *)queue.Dequeue();

                    Cairo.Rectangle(rect->Height, rect->Width, rect->Y, rect->X, MainContext);
                    Cairo.Rectangle(rect->Height, rect->Width, rect->Y, rect->X, VideoContext);

                    Libc.free((uint)rect);

                    update = true;
                }
                Monitor.ReleaseLock(ref RedrawRectsLock);

                if (update)
                {
                    Cairo.Clip(MainContext);
                    var list = Stacking;
                    Monitor.AcquireLock(ref StackingLock);
                    int count = list.Count;
                    for (int index = 0; index < count; index++)
                    {
                        var win = list[index];
                        Cairo.Save(MainContext);
                        Cairo.Translate(win.Y, win.X, MainContext);
                        Cairo.SetSourceSurface(0, 0, win.Surface, MainContext);
                        Cairo.Paint(MainContext);
                        Cairo.Restore(MainContext);
                    }
                    Monitor.ReleaseLock(ref StackingLock);
                }

                if (update)
                {
                    Cairo.Clip(VideoContext);

                    Cairo.Translate(0, 0, VideoContext);
                    Cairo.SetOperator(Operator.Source, VideoContext);
                    Cairo.SetSourceSurface(0, 0, MainSurface, VideoContext);
                    Cairo.Paint(VideoContext);

                    Cairo.Translate(old_mouse_Y, old_mouse_X, VideoContext);
                    Cairo.SetOperator(Operator.Over, VideoContext);
                    Cairo.SetSourceSurface(0, 0, MouseSurface, VideoContext);
                    Cairo.Paint(VideoContext);
                }

                Cairo.Restore(MainContext);
                Cairo.Restore(VideoContext);

                Task.Switch();
            }
        }
示例#4
0
        private static unsafe void HandleMouseEvent(GuiRequest *aRequest)
        {
            var MouseRequest = (MouseEvent *)aRequest;

            MouseRequest->Function = MouseFunction.None;

            MouseFunction function = 0;

            if (MouseRequest->Xpos != 0 || MouseRequest->Ypos != 0)
            {
                function = MouseFunction.Move;
            }

            /* calculate new mouse position */
            int x = Mouse_X + (MouseRequest->Xpos << 1);
            int y = Mouse_Y - (MouseRequest->Ypos << 1);

            /* bound mouse position */
            if (x < 0)
            {
                x = 0;
            }
            if (x > VBE.Xres)
            {
                x = VBE.Xres;
            }

            if (y < 0)
            {
                y = 0;
            }
            if (y > VBE.Yres)
            {
                y = VBE.Yres;
            }

            /* Button Status */
            int  Button   = MouseRequest->Button;
            bool LeftBtn  = (Button & 0x1) != 0;
            bool RightBtn = (Button & 0x2) != 0;

            /* stop window movement */
            if (LeftBtn)
            {
                if (MouseWindow != null)
                {
                    var win = MouseWindow;
                    MarkRectange(win.X, win.Y, win.Width, win.Height);
                    MouseWindow.X += x - Mouse_X;
                    MouseWindow.Y += y - Mouse_Y;
                    MarkRectange(win.X, win.Y, win.Width, win.Height);
                }
            }
            else
            {
                MouseWindow = null;
            }

            /* Update Coordinates */
            Mouse_X = x;
            Mouse_Y = y;

            /* Mouse Events to Client */
            if ((LeftBtn && !MouseLeftBtn) || (RightBtn && !MouseRightBtn))
            {
                function |= MouseFunction.KeyDown;
            }

            if ((!LeftBtn && MouseLeftBtn) || (!RightBtn && MouseRightBtn))
            {
                function |= MouseFunction.KeyUp;
            }

            /* button details */
            MouseLeftBtn   = LeftBtn;
            MouseRightBtn  = RightBtn;
            MouseMiddleBtn = (Button & 0x4) != 0;

            if ((function & MouseFunction.KeyDown) != 0)
            {
                Monitor.AcquireLock(ref StackingLock);

                var list  = Stacking;
                int count = list.Count;
                for (int i = count - 1; i >= 0; i--)
                {
                    var win = list[i];
                    if (x < win.X ||
                        y < win.Y ||
                        x > win.X + win.Width ||
                        y > win.Y + win.Height)
                    {
                        continue;
                    }

                    if (ActiveWindow == win)
                    {
                        function |= MouseFunction.Click;
                        break;
                    }

                    ActiveWindow = win;
                    function    |= MouseFunction.Enter;

                    if (i != 0)
                    {
                        for (int j = i + 1; j < count; j++)
                        {
                            list[j - 1] = list[j];
                        }
                        list[count - 1] = win;

                        MarkRectange(win.X, win.Y, win.Width, win.Height);
                    }
                    break;
                }

                Monitor.ReleaseLock(ref StackingLock);
            }

            if (ActiveWindow == null)
            {
                return;
            }

            var Window = ActiveWindow;

            if (x < Window.X ||
                y < Window.Y ||
                x > Window.X + Window.Width ||
                y > Window.Y + Window.Height)
            {
                return;
            }

            MouseRequest->WindowID = Window.ID;
            MouseRequest->Xpos     = x - Window.X;
            MouseRequest->Ypos     = y - Window.Y;
            MouseRequest->Function = function;
            aRequest->ClientID     = Window.ClientID;
            ReplyClient(aRequest);
        }
示例#5
0
        internal static unsafe uint Obtain(string aID, uint aSize, bool aDoAllocate = false)
        {
            Monitor.AcquireLock(ref aLock);

            if (!Nodes.ContainsKey(aID))
            {
                if (!aDoAllocate)
                {
                    Monitor.ReleaseLock(ref aLock);
                    return(0);
                }
                CreateNew(aID, aSize);
            }

            shm_chunk Current;

            Current = Nodes[aID];
            Current.RefCount++;

            var ParentProcess = Scheduler.RunningThread.Process;
            var shm_mapping   = ParentProcess.shm_mapping;

            int FramesRequired    = Current.Frames.Length;
            int CurrentFrameCount = 0;

            for (int i = 0; i < LIMIT_TO_PROCESS; i++)
            {
                for (int j = 0; j < 32; j++)
                {
                    uint index = (uint)(1 << j);
                    if ((shm_mapping[i] & index) == 0)
                    {
                        CurrentFrameCount++;
                        if (CurrentFrameCount == FramesRequired)
                        {
                            int  xOffset          = (i << 5) + j - FramesRequired + 1;
                            uint xVirtualAddress  = START + (uint)(xOffset << 12);
                            uint xReturnAddress   = xVirtualAddress;
                            var  CurrentDirectory = Paging.CurrentDirectory;
                            var  Frames           = Current.Frames;

                            int Index = 0;
                            while (Index < FramesRequired)
                            {
                                Paging.AllocateFrame(Paging.GetPage(CurrentDirectory, xVirtualAddress, true), (Frames[Index] << 12), false);
                                Paging.InvalidatePageAt(xVirtualAddress);

                                // Also Mark in shm_mapping
                                shm_mapping[(xOffset >> 5)] |= (uint)(0x1 << (xOffset & 31));

                                xVirtualAddress += 0x1000;
                                xOffset++;
                                Index++;
                            }
                            Monitor.ReleaseLock(ref aLock);
                            return(xReturnAddress);
                        }
                    }
                    else
                    {
                        CurrentFrameCount = 0;
                    }
                }
            }

            Monitor.ReleaseLock(ref aLock);
            Debug.Write("shm_mapping failed, Process id:=%d ", ParentProcess.ID);
            Debug.Write("shm_id := %s ", aID);
            Debug.Write("FramesRequired: %d\n", (uint)FramesRequired);
            return(0);
        }