示例#1
0
        static void Main(string[] args)
        {
            WindowManager compositor = new WindowManager();

            WindowManager.Compositor = compositor;

            Console.CancelKeyPress +=
                (sender, e) => {
                Console.WriteLine("CTRL+C detected!\n");
                compositor.Cleanup();
            };

            compositor.KeyDown += delegate(object sender, KeyboardKeyEventArgs e)
            {
                if (!e.IsRepeat)
                {
                    Console.WriteLine(e.Key);
                    if (e.Key == Key.Q)
                    {
                        compositor.Cleanup();
                    }
                    else
                    {
                        state.KeyGetOneSym(EvdevKeyboard.Keycode[e.Key] + 8);
                        state.UpdateKey(EvdevKeyboard.Keycode[e.Key] + 8, 1);
                        Mods[0] = state.SerializeMods(1);
                        Mods[1] = state.SerializeMods(2);
                        Mods[2] = state.SerializeMods(4);
                        Mods[3] = state.SerializeMods(64);
                        CurrentVirtualDesktop.CurrentMode.KeyPress((uint)WindowManager.Time.ElapsedMilliseconds, EvdevKeyboard.Keycode[e.Key], 1);
                    }
                }
            };

            compositor.KeyUp += delegate(object sender, KeyboardKeyEventArgs e)
            {
                if (!e.IsRepeat)
                {
                    state.KeyGetOneSym(EvdevKeyboard.Keycode[e.Key] + 8);
                    state.UpdateKey(EvdevKeyboard.Keycode[e.Key] + 8, 0);
                    Mods[0] = state.SerializeMods(1);
                    Mods[1] = state.SerializeMods(2);
                    Mods[2] = state.SerializeMods(4);
                    Mods[3] = state.SerializeMods(64);
                    CurrentVirtualDesktop.CurrentMode.KeyPress((uint)WindowManager.Time.ElapsedMilliseconds, EvdevKeyboard.Keycode[e.Key], 0);
                }
            };

            compositor.Mouse.ButtonDown += delegate(object sender, MouseButtonEventArgs e)
            {
                CurrentVirtualDesktop.CurrentMode.MouseButton((uint)WindowManager.Time.ElapsedMilliseconds, 0x110, 1);
            };

            compositor.Mouse.ButtonUp += delegate(object sender, MouseButtonEventArgs e)
            {
                CurrentVirtualDesktop.CurrentMode.MouseButton((uint)WindowManager.Time.ElapsedMilliseconds, 0x110, 0);
            };

            compositor.Mouse.Move += delegate(object sender, MouseMoveEventArgs e)
            {
                CurrentVirtualDesktop.CurrentMode.MouseMove((uint)WindowManager.Time.ElapsedMilliseconds, compositor.Mouse.X, compositor.Mouse.Y);
            };

            compositor.InitializeWayland();

            GC.Collect();
            GC.WaitForPendingFinalizers();

            /*
             *      Ideally we'd use a single thread and wait on file descriptors
             *      for Wayland, libinput and DRM events. Instead here we have
             *      separate threads for OpenTK, Wayland and libinput (via OpenTK).
             *      OpenTK by design wants to constantly render even if we have no
             *      changes in what is being displayed. So that we don't use 100%
             *      CPU, the main thread sleeps every loop. This reduces CPU load
             *      to a low level but is still not ideal. Need to think of a way
             *      that we may wait within RenderFrame if there has been no
             *      activity on libinput or wayland.
             */

            compositor.Load += (sender, e) =>
            {
                CurrentVirtualDesktop = new VirtualDesktop(new DesktopMode());
                VirtualDesktops.Add(CurrentVirtualDesktop);
            };

            /*
             * compositor.RenderFrame += (sender, e) =>
             * {
             *
             *      // During initial development use the following
             *      // to check we're not collecting memory that should
             *      // be kept.
             *      //GC.Collect();
             *      //GC.WaitForPendingFinalizers();
             * };
             */
            compositor.Keyboard.KeyRepeat = false;
            compositor.VSync = VSyncMode.Off;
            compositor.Run(1.0, 0.0);
        }
示例#2
0
        static void Main(string[] args)
        {
            WindowManager compositor = new WindowManager();

            Console.CancelKeyPress +=
                (sender, e) => {
                Console.WriteLine("CTRL+C detected!\n");
                display.Terminate();
                System.Diagnostics.Process.GetCurrentProcess().Kill();
            };

            compositor.KeyDown += delegate(object sender, KeyboardKeyEventArgs e) {
                Console.WriteLine(e.Key);
            };

            compositor.KeyUp += delegate(object sender, KeyboardKeyEventArgs e) {
                Console.WriteLine(e.Key);
            };

            compositor.InitializeWayland();

            waylandFinished = new AutoResetEvent(true);
            renderFinished  = new AutoResetEvent(false);
            Thread waylandThread = new Thread(compositor.RunWayland);

            waylandThread.Start();
            GC.Collect();
            GC.WaitForPendingFinalizers();
            //display.Run();

            /*
             *      Ideally we'd use a single thread and wait on file descriptors
             *      for Wayland, libinput and DRM events. Instead here we have
             *      separate threads for OpenTK, Wayland and libinput (via OpenTK).
             *      OpenTK by design wants to constantly render even if we have no
             *      changes in what is being displayed. So that we don't use 100%
             *      CPU, the main thread sleeps every loop. This reduces CPU load
             *      to a low level but is still not ideal. Need to think of a way
             *      that we may wait within RenderFrame if there has been no
             *      activity on libinput or wayland.
             */

            compositor.RenderFrame += (sender, e) =>
            {
                //Console.WriteLine("RENDER: Render waiting on wayland");
                waylandFinished.WaitOne();
                Console.WriteLine("RENDER: Render starting");
                GL.Clear(ClearBufferMask.ColorBufferBit);
                //display.GetEventLoop().Dispatch(5);
                //display.FlushClients();

                lock (surfaces)
                {
                    foreach (ISurface s in surfaces)
                    {
                        SfSurface surface = s.GetSurface();
                        lock (surface)
                        {
                            if (surface.committed)
                            {
                                if (surface.callback != null)
                                {
                                    surface.callback.SendDone(0);
                                    surface.callback.Remove();
                                    surface.callback = null;
                                }
                                surface.committed = false;
                            }
                        }
                    }
                }

                display.FlushClients();
                Console.WriteLine("RENDER: render finished");
                renderFinished.Set();


                compositor.SwapBuffers();
                // Sleep some time to not use 100% CPU...this is a hack
                // Ideally we want to yield to the OS until there is Input
                // from libinput or wayland.
            };
            compositor.VSync = VSyncMode.On;
            compositor.Run(60.0);
        }