Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.3:Update
gnome-remote-desktop
gnome-remote-desktop-0.1.8.obscpio
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File gnome-remote-desktop-0.1.8.obscpio of Package gnome-remote-desktop
07070100000000000041ED000003E800000064000000025E7474AE00000000000000000000000000000000000000000000002600000000gnome-remote-desktop-0.1.8/.gitlab-ci07070100000001000081A4000003E800000064000000015E7474AE0000034C000000000000000000000000000000000000002A00000000gnome-remote-desktop-0.1.8/.gitlab-ci.ymlimage: registry.gitlab.gnome.org/jadahl/gnome-remote-desktop/master:v2 stages: - build - test build-gnome-remote-desktop: stage: build script: - meson . build -Ddebugtype=debugoptimized --werror - ninja -C build - ninja -C build install artifacts: expire_in: 1 day paths: - build test-gnome-remote-desktop: stage: test dependencies: - build-gnome-remote-desktop variables: XDG_RUNTIME_DIR: "$CI_PROJECT_DIR/runtime-dir" GSETTINGS_SCHEMA_DIR: "$CI_PROJECT_DIR/build/src" script: - mkdir -m 700 $XDG_RUNTIME_DIR - glib-compile-schemas $GSETTINGS_SCHEMA_DIR - sed -i 's/.*module-rtkit.*/# &/' /etc/pipewire/pipewire.conf - sed -i 's/.*module-flatpak.*/# &/' /etc/pipewire/pipewire.conf - pipewire & - meson test -C build --no-rebuild --verbose --no-stdsplit -t 10 07070100000002000081A4000003E800000064000000015E7474AE000002DE000000000000000000000000000000000000003100000000gnome-remote-desktop-0.1.8/.gitlab-ci/Dockerfile# Rebuild and push with # # cd .gitlab-ci/ # podman build --format docker --no-cache -t registry.gitlab.gnome.org/jadahl/gnome-remote-desktop/master:v2 . # podman push registry.gitlab.gnome.org/jadahl/gnome-remote-desktop/master:v2 # FROM fedora:32 RUN dnf -y update && dnf -y upgrade && \ dnf install -y 'dnf-command(builddep)' && \ dnf builddep -y gnome-remote-desktop && \ dnf install -y 'pkgconfig(libvncclient)' && \ dnf remove -y pipewire0.2-devel pipewire0.2-libs && \ dnf install -y 'pkgconfig(libpipewire-0.3)' && \ dnf install -y dbus-daemon xorg-x11-server-Xvfb python3-dbus python3-gobject gnome-settings-daemon mesa-dri-drivers xorg-x11-server-Xwayland mutter && \ dnf clean all 07070100000003000081A4000003E800000064000000015E7474AE000046AC000000000000000000000000000000000000002300000000gnome-remote-desktop-0.1.8/COPYING GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the program's name and a brief idea of what it does.> Copyright (C) <year> <name of author> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. <signature of Ty Coon>, 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. 07070100000004000081A4000003E800000064000000015E7474AE0000005B000000000000000000000000000000000000002200000000gnome-remote-desktop-0.1.8/READMEGNOME Remote Desktop ==================== Remote desktop daemon for GNOME using pipewire. 07070100000005000081A4000003E800000064000000015E7474AE000000A4000000000000000000000000000000000000002A00000000gnome-remote-desktop-0.1.8/config.h.meson/* config.h. Generated by meson. */ /* Project version */ #mesondefine VERSION /* The prefix for our gettext translation domains. */ #mesondefine GETTEXT_PACKAGE 07070100000006000081A4000003E800000064000000015E7474AE0000031A000000000000000000000000000000000000003500000000gnome-remote-desktop-0.1.8/gnome-remote-desktop.doap<Project xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:gnome="http://api.gnome.org/doap-extensions#" xmlns="http://usefulinc.com/ns/doap#"> <name xml:lang="en">GNOME Remote Desktop</name> <shortdesc xml:lang="en">Remote desktop service for GNOME</shortdesc> <description>GNOME Remote Desktop implements remote desktop functionality for the GNOME platform.</description> <programming-language>C</programming-language> <maintainer> <foaf:Person> <foaf:name>Jonas Ådahl</foaf:name> <foaf:mbox rdf:resource="mailto:jadahl@redhat.com" /> <gnome:userid>jadahl</gnome:userid> </foaf:Person> </maintainer> </Project> 07070100000007000081A4000003E800000064000000015E7474AE00000519000000000000000000000000000000000000002700000000gnome-remote-desktop-0.1.8/meson.buildproject('gnome-remote-desktop', 'c', version: '0.1.8', meson_version: '>= 0.47.0', default_options: ['warning_level=1', 'buildtype=debugoptimized']) gnome = import('gnome') glib_dep = dependency('glib-2.0') gio_dep = dependency('gio-2.0') gio_unix_dep = dependency('gio-unix-2.0') pipewire_dep = dependency('libpipewire-0.3', version: '>= 0.3.0') systemd_dep = dependency('systemd') libvncserver_dep = dependency('libvncserver') libvncclient_dep = dependency('libvncclient') libsecret_dep = dependency('libsecret-1') libnotify_dep = dependency('libnotify') cdata = configuration_data() cdata.set_quoted('GETTEXT_PACKAGE', 'gnome-remote-desktop') cdata.set_quoted('VERSION', meson.project_version()) configure_file(input: 'config.h.meson', output: 'config.h', configuration: cdata) configinc = include_directories('.') servicedir = get_option('systemd_user_unit_dir') if servicedir == '' servicedir = systemd_dep.get_pkgconfig_variable('systemduserunitdir') endif if servicedir == '' error('Couldn\'t determine systemd user unit service directory') endif top_srcdir = meson.current_source_dir() builddir = meson.current_build_dir() subdir('src') subdir('tests') meson.add_install_script('meson_post_install.py') 07070100000008000081A4000003E800000064000000015E7474AE0000007F000000000000000000000000000000000000002D00000000gnome-remote-desktop-0.1.8/meson_options.txtoption('systemd_user_unit_dir', type: 'string', value: '', description: 'systemd user service directory') 07070100000009000081A4000003E800000064000000015E7474AE0000013A000000000000000000000000000000000000003100000000gnome-remote-desktop-0.1.8/meson_post_install.py#!/usr/bin/env python3 import os import subprocess install_prefix = os.environ['MESON_INSTALL_PREFIX'] schemadir = os.path.join(install_prefix, 'share', 'glib-2.0', 'schemas') if not os.environ.get('DESTDIR'): print('Compiling gsettings schemas...') subprocess.call(['glib-compile-schemas', schemadir]) 0707010000000A000041ED000003E800000064000000025E7474AE00000000000000000000000000000000000000000000001F00000000gnome-remote-desktop-0.1.8/src0707010000000B000081A4000003E800000064000000015E7474AE000000A3000000000000000000000000000000000000003F00000000gnome-remote-desktop-0.1.8/src/gnome-remote-desktop.service.in[Unit] Description=GNOME Remote Desktop [Service] Type=dbus BusName=org.gnome.RemoteDesktop ExecStart=@libexecdir@/gnome-remote-desktop-daemon Restart=on-failure 0707010000000C000081A4000003E800000064000000015E7474AE00000E49000000000000000000000000000000000000002D00000000gnome-remote-desktop-0.1.8/src/grd-context.c/* * Copyright (C) 2015 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by: * Jonas Ådahl <jadahl@gmail.com> */ #include "config.h" #include "grd-context.h" #include "grd-dbus-remote-desktop.h" #include "grd-dbus-screen-cast.h" static const GDebugKey grd_debug_keys[] = { { "vnc", GRD_DEBUG_VNC }, }; struct _GrdContext { GObject parent; GMainContext *main_context; GrdDBusRemoteDesktop *remote_desktop_proxy; GrdDBusScreenCast *screen_cast_proxy; GrdSettings *settings; GList *sessions; GrdDebugFlags debug_flags; }; G_DEFINE_TYPE (GrdContext, grd_context, G_TYPE_OBJECT); GrdDBusRemoteDesktop * grd_context_get_remote_desktop_proxy (GrdContext *context) { return context->remote_desktop_proxy; } GrdDBusScreenCast * grd_context_get_screen_cast_proxy (GrdContext *context) { return context->screen_cast_proxy; } void grd_context_set_remote_desktop_proxy (GrdContext *context, GrdDBusRemoteDesktop *proxy) { context->remote_desktop_proxy = proxy; } void grd_context_set_screen_cast_proxy (GrdContext *context, GrdDBusScreenCast *proxy) { context->screen_cast_proxy = proxy; } GMainContext * grd_context_get_main_context (GrdContext *context) { return context->main_context; } static void on_session_stopped (GrdSession *session, GrdContext *context) { context->sessions = g_list_remove (context->sessions, session); } void grd_context_add_session (GrdContext *context, GrdSession *session) { context->sessions = g_list_append (context->sessions, session); g_signal_connect (session, "stopped", G_CALLBACK (on_session_stopped), context); } GList * grd_context_get_sessions (GrdContext *context) { return context->sessions; } GrdSettings * grd_context_get_settings (GrdContext *context) { return context->settings; } GrdDebugFlags grd_context_get_debug_flags (GrdContext *context) { return context->debug_flags; } static void init_debug_flags (GrdContext *context) { const char *debug_env; debug_env = g_getenv ("GNOME_REMOTE_DESKTOP_DEBUG"); if (debug_env) { context->debug_flags = g_parse_debug_string (debug_env, grd_debug_keys, G_N_ELEMENTS (grd_debug_keys)); } } static void grd_context_finalize (GObject *object) { GrdContext *context = GRD_CONTEXT (object); g_clear_object (&context->settings); G_OBJECT_CLASS (grd_context_parent_class)->finalize (object); } static void grd_context_init (GrdContext *context) { context->main_context = g_main_context_default (); init_debug_flags (context); context->settings = g_object_new (GRD_TYPE_SETTINGS, NULL); } static void grd_context_class_init (GrdContextClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = grd_context_finalize; } 0707010000000D000081A4000003E800000064000000015E7474AE00000867000000000000000000000000000000000000002D00000000gnome-remote-desktop-0.1.8/src/grd-context.h/* * Copyright (C) 2015 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by: * Jonas Ådahl <jadahl@gmail.com> */ #ifndef GRD_CONTEXT_H #define GRD_CONTEXT_H #include <glib-object.h> #include "grd-dbus-remote-desktop.h" #include "grd-dbus-screen-cast.h" #include "grd-settings.h" #include "grd-types.h" typedef enum _GrdDebugFlags { GRD_DEBUG_NONE = 0, GRD_DEBUG_VNC = 1 << 0, } GrdDebugFlags; #define GRD_TYPE_CONTEXT (grd_context_get_type ()) G_DECLARE_FINAL_TYPE (GrdContext, grd_context, GRD, CONTEXT, GObject); GrdDBusRemoteDesktop * grd_context_get_remote_desktop_proxy (GrdContext *context); GrdDBusScreenCast * grd_context_get_screen_cast_proxy (GrdContext *context); void grd_context_set_remote_desktop_proxy (GrdContext *context, GrdDBusRemoteDesktop *proxy); void grd_context_set_screen_cast_proxy (GrdContext *context, GrdDBusScreenCast *proxy); GrdPipeWireStreamMonitor *grd_context_get_pipewire_stream_monitor (GrdContext *context); GMainContext *grd_context_get_main_context (GrdContext *context); void grd_context_add_session (GrdContext *context, GrdSession *session); GList * grd_context_get_sessions (GrdContext *context); GrdSettings * grd_context_get_settings (GrdContext *context); GrdDebugFlags grd_context_get_debug_flags (GrdContext *context); #endif /* GRD_CONTEXT_H */ 0707010000000E000081A4000003E800000064000000015E7474AE000008DE000000000000000000000000000000000000002D00000000gnome-remote-desktop-0.1.8/src/grd-control.c/* * Copyright (C) 2015 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by: * Jonas Ådahl <jadahl@gmail.com> */ #include "config.h" #include <gio/gio.h> #include <stdio.h> #include <string.h> #include "grd-private.h" int main (int argc, char **argv) { g_autoptr(GApplication) app = NULL; gboolean terminate = FALSE; GOptionEntry entries[] = { { "terminate", 0, 0, G_OPTION_ARG_NONE, &terminate, "Terminate the daemon", NULL }, { NULL } }; GError *error = NULL; GOptionContext *context; context = g_option_context_new ("- control gnome-remote-desktop"); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("Invalid option: %s\n", error->message); g_error_free (error); return 1; } if (!terminate) { g_printerr ("%s", g_option_context_get_help (context, TRUE, NULL)); return 1; } app = g_application_new (GRD_DAEMON_APPLICATION_ID, 0); if (!g_application_register (app, NULL, NULL)) { g_warning ("Failed to register with application\n"); return 1; } if (!g_application_get_is_registered (app)) { g_warning ("Not registered\n"); return 1; } if (!g_application_get_is_remote (app)) { g_warning ("Failed to connect to application\n"); return 1; } if (terminate) g_action_group_activate_action (G_ACTION_GROUP (app), "terminate", NULL); else g_assert_not_reached (); return 0; } 0707010000000F000081A4000003E800000064000000015E7474AE0000244D000000000000000000000000000000000000002C00000000gnome-remote-desktop-0.1.8/src/grd-daemon.c/* * Copyright (C) 2015 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by: * Jonas Ådahl <jadahl@gmail.com> */ #include "config.h" #include "grd-daemon.h" #include <gio/gio.h> #include <glib/gi18n.h> #include <stdio.h> #include <stdlib.h> #include "grd-context.h" #include "grd-dbus-remote-desktop.h" #include "grd-private.h" #include "grd-session.h" #include "grd-vnc-server.h" struct _GrdDaemon { GApplication parent; GCancellable *cancellable; guint remote_desktop_watch_name_id; guint screen_cast_watch_name_id; GrdContext *context; GrdVncServer *vnc_server; }; G_DEFINE_TYPE (GrdDaemon, grd_daemon, G_TYPE_APPLICATION) static gboolean is_daemon_ready (GrdDaemon *daemon) { if (!grd_context_get_remote_desktop_proxy (daemon->context) || !grd_context_get_screen_cast_proxy (daemon->context)) return FALSE; return TRUE; } static void maybe_enable_services (GrdDaemon *daemon) { GError *error = NULL; if (!is_daemon_ready (daemon)) return; daemon->vnc_server = grd_vnc_server_new (daemon->context); if (!grd_vnc_server_start (daemon->vnc_server, &error)) { g_warning ("Failed to initialize VNC server: %s\n", error->message); } } static void close_all_sessions (GrdDaemon *daemon) { GList *l; while ((l = grd_context_get_sessions (daemon->context))) { GrdSession *session = l->data; grd_session_stop (session); } } static void disable_services (GrdDaemon *daemon) { close_all_sessions (daemon); g_clear_object (&daemon->vnc_server); } static void on_remote_desktop_proxy_acquired (GObject *object, GAsyncResult *result, gpointer user_data) { GrdDaemon *daemon = user_data; GrdDBusRemoteDesktop *proxy; GError *error = NULL; proxy = grd_dbus_remote_desktop_proxy_new_for_bus_finish (result, &error); if (!proxy) { g_warning ("Failed to create remote desktop proxy: %s", error->message); g_error_free (error); return; } grd_context_set_remote_desktop_proxy (daemon->context, proxy); maybe_enable_services (daemon); } static void on_screen_cast_proxy_acquired (GObject *object, GAsyncResult *result, gpointer user_data) { GrdDaemon *daemon = user_data; GrdDBusScreenCast *proxy; GError *error = NULL; proxy = grd_dbus_screen_cast_proxy_new_for_bus_finish (result, &error); if (!proxy) { g_warning ("Failed to create screen cast proxy: %s", error->message); return; } grd_context_set_screen_cast_proxy (daemon->context, proxy); maybe_enable_services (daemon); } static void on_remote_desktop_name_appeared (GDBusConnection *connection, const char *name, const char *name_owner, gpointer user_data) { GrdDaemon *daemon = user_data; grd_dbus_remote_desktop_proxy_new_for_bus (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, MUTTER_REMOTE_DESKTOP_BUS_NAME, MUTTER_REMOTE_DESKTOP_OBJECT_PATH, daemon->cancellable, on_remote_desktop_proxy_acquired, daemon); } static void on_remote_desktop_name_vanished (GDBusConnection *connection, const char *name, gpointer user_data) { GrdDaemon *daemon = user_data; disable_services (daemon); grd_context_set_remote_desktop_proxy (daemon->context, NULL); } static void on_screen_cast_name_appeared (GDBusConnection *connection, const char *name, const char *name_owner, gpointer user_data) { GrdDaemon *daemon = user_data; grd_dbus_screen_cast_proxy_new_for_bus (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, MUTTER_SCREEN_CAST_BUS_NAME, MUTTER_SCREEN_CAST_OBJECT_PATH, daemon->cancellable, on_screen_cast_proxy_acquired, daemon); } static void on_screen_cast_name_vanished (GDBusConnection *connection, const char *name, gpointer user_data) { GrdDaemon *daemon = user_data; disable_services (daemon); grd_context_set_screen_cast_proxy (daemon->context, NULL); } static void grd_daemon_init (GrdDaemon *daemon) { daemon->context = g_object_new (GRD_TYPE_CONTEXT, NULL); } static void grd_daemon_startup (GApplication *app) { GrdDaemon *daemon = GRD_DAEMON (app); daemon->remote_desktop_watch_name_id = g_bus_watch_name (G_BUS_TYPE_SESSION, MUTTER_REMOTE_DESKTOP_BUS_NAME, G_BUS_NAME_WATCHER_FLAGS_NONE, on_remote_desktop_name_appeared, on_remote_desktop_name_vanished, daemon, NULL); daemon->screen_cast_watch_name_id = g_bus_watch_name (G_BUS_TYPE_SESSION, MUTTER_SCREEN_CAST_BUS_NAME, G_BUS_NAME_WATCHER_FLAGS_NONE, on_screen_cast_name_appeared, on_screen_cast_name_vanished, daemon, NULL); daemon->cancellable = g_cancellable_new (); /* Run indefinitely, until told to exit. */ g_application_hold (app); G_APPLICATION_CLASS (grd_daemon_parent_class)->startup (app); } static void grd_daemon_shutdown (GApplication *app) { GrdDaemon *daemon = GRD_DAEMON (app); g_cancellable_cancel (daemon->cancellable); g_clear_object (&daemon->cancellable); disable_services (daemon); grd_context_set_remote_desktop_proxy (daemon->context, NULL); g_bus_unwatch_name (daemon->remote_desktop_watch_name_id); daemon->remote_desktop_watch_name_id = 0; grd_context_set_screen_cast_proxy (daemon->context, NULL); g_bus_unwatch_name (daemon->screen_cast_watch_name_id); daemon->screen_cast_watch_name_id = 0; G_APPLICATION_CLASS (grd_daemon_parent_class)->shutdown (app); } static void grd_daemon_class_init (GrdDaemonClass *klass) { GApplicationClass *g_application_class = G_APPLICATION_CLASS (klass); g_application_class->startup = grd_daemon_startup; g_application_class->shutdown = grd_daemon_shutdown; } static void activate_terminate (GAction *action, GVariant *parameter, GrdDaemon *daemon) { g_application_release (G_APPLICATION (daemon)); } static void add_actions (GApplication *app) { g_autoptr(GSimpleAction) action = NULL; action = g_simple_action_new ("terminate", NULL); g_signal_connect (action, "activate", G_CALLBACK (activate_terminate), app); g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action)); } int main (int argc, char **argv) { gboolean print_version = FALSE; int vnc_port = -1; GOptionEntry entries[] = { { "version", 0, 0, G_OPTION_ARG_NONE, &print_version, "Print version", NULL }, { "vnc-port", 0, 0, G_OPTION_ARG_INT, &vnc_port, "VNC port", NULL }, { NULL } }; g_autoptr(GOptionContext) context = NULL; g_autoptr(GApplication) app = NULL; GError *error = NULL; g_set_application_name (_("GNOME Remote Desktop")); context = g_option_context_new (NULL); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("Invalid option: %s\n", error->message); g_error_free (error); return EXIT_FAILURE; } if (print_version) { g_print ("GNOME Remote Desktop %s\n", VERSION); return EXIT_SUCCESS; } app = g_object_new (GRD_TYPE_DAEMON, "application-id", GRD_DAEMON_APPLICATION_ID, "flags", G_APPLICATION_IS_SERVICE, NULL); add_actions (app); if (vnc_port != -1) { GrdSettings *settings; settings = grd_context_get_settings (GRD_DAEMON (app)->context); grd_settings_override_vnc_port (settings, vnc_port); } return g_application_run (app, argc, argv); } 07070100000010000081A4000003E800000064000000015E7474AE0000049C000000000000000000000000000000000000002C00000000gnome-remote-desktop-0.1.8/src/grd-daemon.h/* * Copyright (C) 2015 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by: * Jonas Ådahl <jadahl@gmail.com> */ #ifndef GRD_DAEMON_H #define GRD_DAEMON_H #include <gio/gio.h> #include "grd-dbus-remote-desktop.h" typedef struct _GrdDaemon GrdDaemon; #define GRD_TYPE_DAEMON (grd_daemon_get_type ()) G_DECLARE_FINAL_TYPE (GrdDaemon, grd_daemon, GRD, DAEMON, GApplication); GrdDBusRemoteDesktop *grd_daemon_get_dbus_proxy (GrdDaemon *daemon); #endif /* GRD_DAEMON_H */ 07070100000011000081A4000003E800000064000000015E7474AE000003A1000000000000000000000000000000000000002B00000000gnome-remote-desktop-0.1.8/src/grd-enums.h/* * Copyright (C) 2018 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * */ #ifndef GRD_ENUMS_H #define GRD_ENUMS_H typedef enum { GRD_VNC_AUTH_METHOD_PROMPT, GRD_VNC_AUTH_METHOD_PASSWORD } GrdVncAuthMethod; #endif /* GRD_ENUMS_H */ 07070100000012000081A4000003E800000064000000015E7474AE000004D5000000000000000000000000000000000000002D00000000gnome-remote-desktop-0.1.8/src/grd-private.h/* * Copyright (C) 2015 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by: * Jonas Ådahl <jadahl@gmail.com> */ #ifndef GRD_PRIVATE_H #define GRD_PRIVATE_H #define GRD_DAEMON_APPLICATION_ID "org.gnome.RemoteDesktop" #define MUTTER_REMOTE_DESKTOP_BUS_NAME "org.gnome.Mutter.RemoteDesktop" #define MUTTER_REMOTE_DESKTOP_OBJECT_PATH "/org/gnome/Mutter/RemoteDesktop" #define MUTTER_SCREEN_CAST_BUS_NAME "org.gnome.Mutter.ScreenCast" #define MUTTER_SCREEN_CAST_OBJECT_PATH "/org/gnome/Mutter/ScreenCast" #endif /* GRD_PRIVATE_H */ 07070100000013000081A4000003E800000064000000015E7474AE0000147E000000000000000000000000000000000000002C00000000gnome-remote-desktop-0.1.8/src/grd-prompt.c/* * Copyright (C) 2018 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * */ #include "config.h" #include <glib/gi18n.h> #include <libnotify/notify.h> #include "grd-prompt.h" typedef struct _GrdPromptResult { GrdPromptResponse response; } GrdPromptResult; struct _GrdPrompt { GObject parent; }; G_DEFINE_TYPE (GrdPrompt, grd_prompt, G_TYPE_OBJECT) static void handle_notification_response (NotifyNotification *notification, char *response, gpointer user_data) { GTask *task = G_TASK (user_data); if (g_strcmp0 (response, "accept") == 0) { g_task_return_int (task, GRD_PROMPT_RESPONSE_ACCEPT); } else if (g_strcmp0 (response, "refuse") == 0 || g_strcmp0 (response, "closed") == 0) { g_task_return_int (task, GRD_PROMPT_RESPONSE_REFUSE); } else { g_warning ("Unknown prompt response '%s'", response); g_task_return_int (task, GRD_PROMPT_RESPONSE_REFUSE); } } static void on_notification_closed (NotifyNotification *notification, gpointer user_data) { handle_notification_response (notification, "closed", user_data); } static gboolean cancelled_idle_callback (gpointer user_data) { GTask *task = G_TASK (user_data); g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_CANCELLED, "Prompt was cancelled"); return G_SOURCE_REMOVE; } static void on_cancellable_cancelled (GCancellable *cancellable, GTask *task) { NotifyNotification *notification = NOTIFY_NOTIFICATION (g_task_get_task_data (task)); notify_notification_close (notification, NULL); g_idle_add (cancelled_idle_callback, task); } static gboolean show_notification_idle_callback (gpointer user_data) { GTask *task = G_TASK (user_data); GCancellable *cancellable = g_task_get_cancellable (task); NotifyNotification *notification; GError *error = NULL; if (g_cancellable_is_cancelled (cancellable)) return G_SOURCE_REMOVE; notification = g_task_get_task_data (task); if (!notify_notification_show (notification, &error)) g_task_return_error (task, error); return G_SOURCE_REMOVE; } void grd_prompt_query_async (GrdPrompt *prompt, const char *remote_host, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { NotifyNotification *notification; GTask *task; g_autofree char *summary = NULL; g_autofree char *body = NULL; task = g_task_new (G_OBJECT (prompt), cancellable, callback, user_data); summary = g_strdup_printf (_("Do you want to share your desktop?")); body = g_strdup_printf (_("A user on the computer '%s' is trying to remotely view or control your desktop."), remote_host); notification = notify_notification_new (summary, body, "preferences-desktop-remote-desktop"); notify_notification_add_action (notification, "refuse", _("Refuse"), handle_notification_response, task, NULL); notify_notification_add_action (notification, "accept", _("Accept"), handle_notification_response, task, NULL); g_task_set_task_data (task, notification, g_object_unref); g_signal_connect (notification, "closed", G_CALLBACK (on_notification_closed), task); g_cancellable_connect (cancellable, G_CALLBACK (on_cancellable_cancelled), task, NULL); g_idle_add (show_notification_idle_callback, task); } gboolean grd_prompt_query_finish (GrdPrompt *prompt, GAsyncResult *result, GrdPromptResponse *out_response, GError **error) { g_autoptr(GTask) task = G_TASK (result); GrdPromptResponse response; response = g_task_propagate_int (task, error); if (response == -1) return FALSE; *out_response = response; return TRUE; } static void grd_prompt_init (GrdPrompt *prompt) { } static void grd_prompt_class_init (GrdPromptClass *klass) { notify_init (g_get_application_name ()); } 07070100000014000081A4000003E800000064000000015E7474AE00000659000000000000000000000000000000000000002C00000000gnome-remote-desktop-0.1.8/src/grd-prompt.h/* * Copyright (C) 2018 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * */ #ifndef GRD_PROMPT_H #define GRD_PROMPT_H typedef enum _GrdPromptResponse { GRD_PROMPT_RESPONSE_ACCEPT, GRD_PROMPT_RESPONSE_REFUSE } GrdPromptResponse; #define GRD_TYPE_PROMPT (grd_prompt_get_type ()) G_DECLARE_FINAL_TYPE (GrdPrompt, grd_prompt, GRD, PROMPT, GObject) void grd_prompt_query_async (GrdPrompt *prompt, const char *remote_host, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean grd_prompt_query_finish (GrdPrompt *prompt, GAsyncResult *result, GrdPromptResponse *response, GError **error); #endif /* GRD_PROMPT_H */ 07070100000015000081A4000003E800000064000000015E7474AE00004EA7000000000000000000000000000000000000003100000000gnome-remote-desktop-0.1.8/src/grd-session-vnc.c/* * Copyright (C) 2015 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by: * Jonas Ådahl <jadahl@gmail.com> */ #include "config.h" #include "grd-session-vnc.h" #include <gio/gio.h> #include <linux/input.h> #include <rfb/rfb.h> #include "grd-context.h" #include "grd-prompt.h" #include "grd-settings.h" #include "grd-stream.h" #include "grd-vnc-server.h" #include "grd-vnc-pipewire-stream.h" /* BGRx */ #define BGRX_BITS_PER_SAMPLE 8 #define BGRX_SAMPLES_PER_PIXEL 3 #define BGRX_BYTES_PER_PIXEL 4 struct _GrdSessionVnc { GrdSession parent; GSocketConnection *connection; GSource *source; rfbScreenInfoPtr rfb_screen; rfbClientPtr rfb_client; gboolean pending_framebuffer_resize; int pending_framebuffer_width; int pending_framebuffer_height; guint close_session_idle_id; GrdVncAuthMethod auth_method; GrdPrompt *prompt; GCancellable *prompt_cancellable; GrdVncPipeWireStream *pipewire_stream; int prev_x; int prev_y; int prev_button_mask; GHashTable *pressed_keys; }; G_DEFINE_TYPE (GrdSessionVnc, grd_session_vnc, GRD_TYPE_SESSION); static void grd_session_vnc_detach_source (GrdSessionVnc *session_vnc); static gboolean close_session_idle (gpointer user_data); static rfbBool check_rfb_password (rfbClientPtr rfb_client, const char *response_encrypted, int len); static void swap_uint8 (uint8_t *a, uint8_t *b) { uint8_t tmp; tmp = *a; *a = *b; *b = tmp; } static void update_server_format (GrdSessionVnc *session_vnc) { rfbScreenInfoPtr rfb_screen = session_vnc->rfb_screen; /* * Our format is hard coded to BGRX but LibVNCServer assumes it's RGBX; * lets override that. */ swap_uint8 (&rfb_screen->serverFormat.redShift, &rfb_screen->serverFormat.blueShift); } static void resize_vnc_framebuffer (GrdSessionVnc *session_vnc, int width, int height) { rfbScreenInfoPtr rfb_screen = session_vnc->rfb_screen; uint8_t *framebuffer; if (!session_vnc->rfb_client->useNewFBSize) g_warning ("Client does not support NewFBSize"); g_free (rfb_screen->frameBuffer); framebuffer = g_malloc0 (width * height * BGRX_BYTES_PER_PIXEL); rfbNewFramebuffer (rfb_screen, (char *) framebuffer, width, height, BGRX_BITS_PER_SAMPLE, BGRX_SAMPLES_PER_PIXEL, BGRX_BYTES_PER_PIXEL); update_server_format (session_vnc); rfb_screen->setTranslateFunction (session_vnc->rfb_client); } void grd_session_vnc_queue_resize_framebuffer (GrdSessionVnc *session_vnc, int width, int height) { rfbScreenInfoPtr rfb_screen = session_vnc->rfb_screen; if (rfb_screen->width == width && rfb_screen->height == height) return; if (session_vnc->rfb_client->preferredEncoding == -1) { session_vnc->pending_framebuffer_resize = TRUE; session_vnc->pending_framebuffer_width = width; session_vnc->pending_framebuffer_height = height; return; } resize_vnc_framebuffer (session_vnc, width, height); } void grd_session_vnc_take_buffer (GrdSessionVnc *session_vnc, void *data) { if (session_vnc->pending_framebuffer_resize) { free (data); return; } free (session_vnc->rfb_screen->frameBuffer); session_vnc->rfb_screen->frameBuffer = data; rfbMarkRectAsModified (session_vnc->rfb_screen, 0, 0, session_vnc->rfb_screen->width, session_vnc->rfb_screen->height); rfbProcessEvents (session_vnc->rfb_screen, 0); } void grd_session_vnc_set_cursor (GrdSessionVnc *session_vnc, rfbCursorPtr rfb_cursor) { rfbSetCursor (session_vnc->rfb_screen, rfb_cursor); } void grd_session_vnc_move_cursor (GrdSessionVnc *session_vnc, int x, int y) { if (session_vnc->rfb_screen->cursorX == x || session_vnc->rfb_screen->cursorY == y) return; LOCK (session_vnc->rfb_screen->cursorMutex); session_vnc->rfb_screen->cursorX = x; session_vnc->rfb_screen->cursorY = y; UNLOCK (session_vnc->rfb_screen->cursorMutex); session_vnc->rfb_client->cursorWasMoved = TRUE; } static void maybe_queue_close_session_idle (GrdSessionVnc *session_vnc) { if (session_vnc->close_session_idle_id) return; session_vnc->close_session_idle_id = g_idle_add (close_session_idle, session_vnc); } static void handle_client_gone (rfbClientPtr rfb_client) { GrdSessionVnc *session_vnc = rfb_client->screen->screenData; g_debug ("VNC client gone"); grd_session_vnc_detach_source (session_vnc); maybe_queue_close_session_idle (session_vnc); } static void prompt_response_callback (GObject *source_object, GAsyncResult *async_result, gpointer user_data) { GrdSessionVnc *session_vnc = GRD_SESSION_VNC (user_data); g_autoptr(GError) error = NULL; GrdPromptResponse response; if (!grd_prompt_query_finish (session_vnc->prompt, async_result, &response, &error)) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { g_warning ("Failed to query user about session: %s", error->message); rfbRefuseOnHoldClient (session_vnc->rfb_client); return; } else { return; } } switch (response) { case GRD_PROMPT_RESPONSE_ACCEPT: grd_session_start (GRD_SESSION (session_vnc)); rfbStartOnHoldClient (session_vnc->rfb_client); return; case GRD_PROMPT_RESPONSE_REFUSE: rfbRefuseOnHoldClient (session_vnc->rfb_client); return; } g_assert_not_reached (); } static enum rfbNewClientAction handle_new_client (rfbClientPtr rfb_client) { GrdSessionVnc *session_vnc = GRD_SESSION_VNC (rfb_client->screen->screenData); GrdContext *context = grd_session_get_context (GRD_SESSION (session_vnc)); GrdSettings *settings = grd_context_get_settings (context); g_debug ("New VNC client"); session_vnc->auth_method = grd_settings_get_vnc_auth_method (settings); session_vnc->rfb_client = rfb_client; rfb_client->clientGoneHook = handle_client_gone; switch (session_vnc->auth_method) { case GRD_VNC_AUTH_METHOD_PROMPT: session_vnc->prompt = g_object_new (GRD_TYPE_PROMPT, NULL); session_vnc->prompt_cancellable = g_cancellable_new (); grd_prompt_query_async (session_vnc->prompt, rfb_client->host, session_vnc->prompt_cancellable, prompt_response_callback, session_vnc); grd_session_vnc_detach_source (session_vnc); return RFB_CLIENT_ON_HOLD; case GRD_VNC_AUTH_METHOD_PASSWORD: session_vnc->rfb_screen->passwordCheck = check_rfb_password; /* * authPasswdData needs to be non NULL in libvncserver to trigger * password authentication. */ session_vnc->rfb_screen->authPasswdData = (gpointer) 1; return RFB_CLIENT_ACCEPT; } g_assert_not_reached (); } static gboolean is_view_only (GrdSessionVnc *session_vnc) { GrdContext *context = grd_session_get_context (GRD_SESSION (session_vnc)); GrdSettings *settings = grd_context_get_settings (context); return grd_settings_get_vnc_view_only (settings); } static void handle_key_event (rfbBool down, rfbKeySym keysym, rfbClientPtr rfb_client) { GrdSessionVnc *session_vnc = GRD_SESSION_VNC (rfb_client->screen->screenData); GrdSession *session = GRD_SESSION (session_vnc); if (is_view_only (session_vnc)) return; if (down) { if (g_hash_table_add (session_vnc->pressed_keys, GUINT_TO_POINTER (keysym))) { grd_session_notify_keyboard_keysym (session, keysym, GRD_KEY_STATE_PRESSED); } } else { if (g_hash_table_remove (session_vnc->pressed_keys, GUINT_TO_POINTER (keysym))) { grd_session_notify_keyboard_keysym (session, keysym, GRD_KEY_STATE_RELEASED); } } } static gboolean notify_keyboard_key_released (gpointer key, gpointer value, gpointer user_data) { GrdSession *session = user_data; uint32_t keysym = GPOINTER_TO_UINT (key); grd_session_notify_keyboard_keysym (session, keysym, GRD_KEY_STATE_RELEASED); return TRUE; } static void handle_release_all_keys (rfbClientPtr rfb_client) { GrdSessionVnc *session_vnc = rfb_client->screen->screenData; g_hash_table_foreach_remove (session_vnc->pressed_keys, notify_keyboard_key_released, session_vnc); } static void grd_session_vnc_notify_axis (GrdSessionVnc *session_vnc, int button_mask_bit_index) { GrdSession *session = GRD_SESSION (session_vnc); GrdPointerAxis axis; int steps; switch (button_mask_bit_index) { case 3: axis = GRD_POINTER_AXIS_VERTICAL; steps = -1; break; case 4: axis = GRD_POINTER_AXIS_VERTICAL; steps = 1; break; case 5: axis = GRD_POINTER_AXIS_HORIZONTAL; steps = -1; break; case 6: axis = GRD_POINTER_AXIS_HORIZONTAL; steps = 1; break; default: return; } grd_session_notify_pointer_axis_discrete (session, axis, steps); } static void handle_pointer_event (int button_mask, int x, int y, rfbClientPtr rfb_client) { GrdSessionVnc *session_vnc = rfb_client->screen->screenData; GrdSession *session = GRD_SESSION (session_vnc); if (is_view_only (session_vnc)) return; if (x != session_vnc->prev_x || y != session_vnc->prev_y) { grd_session_notify_pointer_motion_absolute (session, x, y); session_vnc->prev_x = x; session_vnc->prev_y = y; } if (button_mask != session_vnc->prev_button_mask) { unsigned int i; int buttons[] = { BTN_LEFT, /* 0 */ BTN_MIDDLE, /* 1 */ BTN_RIGHT, /* 2 */ 0, /* 3 - vertical scroll: up */ 0, /* 4 - vertical scroll: down */ 0, /* 5 - horizontal scroll: left */ 0, /* 6 - horizontal scroll: right */ BTN_SIDE, /* 7 */ BTN_EXTRA, /* 8 */ }; for (i = 0; i < G_N_ELEMENTS (buttons); i++) { int button = buttons[i]; int prev_button_state = (session_vnc->prev_button_mask >> i) & 0x01; int cur_button_state = (button_mask >> i) & 0x01; if (prev_button_state != cur_button_state) { if (button) { grd_session_notify_pointer_button (session, button, cur_button_state); } else { grd_session_vnc_notify_axis (session_vnc, i); } } } session_vnc->prev_button_mask = button_mask; } rfbDefaultPtrAddEvent (button_mask, x, y, rfb_client); } static rfbBool check_rfb_password (rfbClientPtr rfb_client, const char *response_encrypted, int len) { GrdSessionVnc *session_vnc = rfb_client->screen->screenData; GrdContext *context = grd_session_get_context (GRD_SESSION (session_vnc)); GrdSettings *settings = grd_context_get_settings (context); g_autofree char *password = NULL; g_autoptr(GError) error = NULL; uint8_t challenge_encrypted[CHALLENGESIZE]; switch (session_vnc->auth_method) { case GRD_VNC_AUTH_METHOD_PROMPT: return TRUE; case GRD_VNC_AUTH_METHOD_PASSWORD: break; } password = grd_settings_get_vnc_password (settings, &error); if (!password) { g_warning ("Couldn't retrieve VNC password: %s", error->message); return FALSE; } if (strlen (password) == 0) { g_warning ("VNC password was empty, denying"); return FALSE; } memcpy(challenge_encrypted, rfb_client->authChallenge, CHALLENGESIZE); rfbEncryptBytes(challenge_encrypted, password); if (memcmp (challenge_encrypted, response_encrypted, len) == 0) { grd_session_start (GRD_SESSION (session_vnc)); grd_session_vnc_detach_source (session_vnc); return TRUE; } else { return FALSE; } } int grd_session_vnc_get_framebuffer_stride (GrdSessionVnc *session_vnc) { return session_vnc->rfb_screen->paddedWidthInBytes; } static void init_vnc_session (GrdSessionVnc *session_vnc) { GSocket *socket; int screen_width; int screen_height; rfbScreenInfoPtr rfb_screen; /* Arbitrary framebuffer size, will get the proper size from the stream. */ screen_width = 800; screen_height = 600; rfb_screen = rfbGetScreen (0, NULL, screen_width, screen_height, 8, 3, 4); session_vnc->rfb_screen = rfb_screen; update_server_format (session_vnc); socket = g_socket_connection_get_socket (session_vnc->connection); rfb_screen->inetdSock = g_socket_get_fd (socket); rfb_screen->desktopName = "GNOME"; rfb_screen->versionString = "GNOME Remote Desktop (VNC)"; rfb_screen->neverShared = TRUE; rfb_screen->newClientHook = handle_new_client; rfb_screen->screenData = session_vnc; /* Amount of milliseconds to wait before sending an update */ rfb_screen->deferUpdateTime = 0; rfb_screen->kbdAddEvent = handle_key_event; rfb_screen->kbdReleaseAllKeys = handle_release_all_keys; rfb_screen->ptrAddEvent = handle_pointer_event; rfb_screen->frameBuffer = g_malloc0 (screen_width * screen_height * 4); memset (rfb_screen->frameBuffer, 0x1f, screen_width * screen_height * 4); rfbInitServer (rfb_screen); rfbProcessEvents (rfb_screen, 0); } static gboolean handle_socket_data (GSocket *socket, GIOCondition condition, gpointer user_data) { GrdSessionVnc *session_vnc = user_data; if (condition & G_IO_IN) { if (rfbIsActive (session_vnc->rfb_screen)) { rfbProcessEvents (session_vnc->rfb_screen, 0); if (session_vnc->pending_framebuffer_resize && session_vnc->rfb_client->preferredEncoding != -1) { resize_vnc_framebuffer (session_vnc, session_vnc->pending_framebuffer_width, session_vnc->pending_framebuffer_height); session_vnc->pending_framebuffer_resize = FALSE; } } } else { g_debug ("Unhandled socket condition %d\n", condition); return G_SOURCE_REMOVE; } return G_SOURCE_CONTINUE; } static void grd_session_vnc_attach_source (GrdSessionVnc *session_vnc) { GSocket *socket; socket = g_socket_connection_get_socket (session_vnc->connection); session_vnc->source = g_socket_create_source (socket, G_IO_IN | G_IO_PRI, NULL); g_source_set_callback (session_vnc->source, (GSourceFunc) handle_socket_data, session_vnc, NULL); g_source_attach (session_vnc->source, NULL); } static void grd_session_vnc_detach_source (GrdSessionVnc *session_vnc) { g_clear_pointer (&session_vnc->source, g_source_destroy); } GrdSessionVnc * grd_session_vnc_new (GrdVncServer *vnc_server, GSocketConnection *connection) { GrdSessionVnc *session_vnc; GrdContext *context; context = grd_vnc_server_get_context (vnc_server); session_vnc = g_object_new (GRD_TYPE_SESSION_VNC, "context", context, NULL); session_vnc->connection = g_object_ref (connection); grd_session_vnc_attach_source (session_vnc); init_vnc_session (session_vnc); return session_vnc; } static void grd_session_vnc_dispose (GObject *object) { GrdSessionVnc *session_vnc = GRD_SESSION_VNC (object); g_assert (!session_vnc->rfb_screen); g_clear_pointer (&session_vnc->pressed_keys, g_hash_table_unref); G_OBJECT_CLASS (grd_session_vnc_parent_class)->dispose (object); } static void grd_session_vnc_stop (GrdSession *session) { GrdSessionVnc *session_vnc = GRD_SESSION_VNC (session); g_debug ("Stopping VNC session"); g_clear_object (&session_vnc->pipewire_stream); grd_session_vnc_detach_source (session_vnc); g_clear_object (&session_vnc->connection); g_clear_pointer (&session_vnc->rfb_screen->frameBuffer, g_free); g_clear_pointer (&session_vnc->rfb_screen, rfbScreenCleanup); if (session_vnc->close_session_idle_id) { g_source_remove (session_vnc->close_session_idle_id); session_vnc->close_session_idle_id = 0; } } static gboolean close_session_idle (gpointer user_data) { GrdSessionVnc *session_vnc = GRD_SESSION_VNC (user_data); grd_session_stop (GRD_SESSION (session_vnc)); session_vnc->close_session_idle_id = 0; return G_SOURCE_REMOVE; } static void on_pipwire_stream_closed (GrdVncPipeWireStream *stream, GrdSessionVnc *session_vnc) { g_warning ("PipeWire stream closed, closing client"); maybe_queue_close_session_idle (session_vnc); } static void grd_session_vnc_stream_ready (GrdSession *session, GrdStream *stream) { GrdSessionVnc *session_vnc = GRD_SESSION_VNC (session); uint32_t pipewire_node_id; g_autoptr (GError) error = NULL; pipewire_node_id = grd_stream_get_pipewire_node_id (stream); session_vnc->pipewire_stream = grd_vnc_pipewire_stream_new (session_vnc, pipewire_node_id, &error); if (!session_vnc->pipewire_stream) { g_warning ("Failed to establish PipeWire stream: %s", error->message); return; } g_signal_connect (session_vnc->pipewire_stream, "closed", G_CALLBACK (on_pipwire_stream_closed), session_vnc); if (!session_vnc->source) grd_session_vnc_attach_source (session_vnc); } static void grd_session_vnc_init (GrdSessionVnc *session_vnc) { session_vnc->pressed_keys = g_hash_table_new (NULL, NULL); } static void grd_session_vnc_class_init (GrdSessionVncClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GrdSessionClass *session_class = GRD_SESSION_CLASS (klass); object_class->dispose = grd_session_vnc_dispose; session_class->stop = grd_session_vnc_stop; session_class->stream_ready = grd_session_vnc_stream_ready; } 07070100000016000081A4000003E800000064000000015E7474AE00000814000000000000000000000000000000000000003100000000gnome-remote-desktop-0.1.8/src/grd-session-vnc.h/* * Copyright (C) 2015 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by: * Jonas Ådahl <jadahl@gmail.com> */ #ifndef GRD_SESSION_VNC_H #define GRD_SESSION_VNC_H #include <gio/gio.h> #include <glib-object.h> #include <rfb/rfb.h> #include "grd-session.h" #include "grd-types.h" #define GRD_TYPE_SESSION_VNC (grd_session_vnc_get_type ()) G_DECLARE_FINAL_TYPE (GrdSessionVnc, grd_session_vnc, GRD, SESSION_VNC, GrdSession); GrdSessionVnc *grd_session_vnc_new (GrdVncServer *vnc_server, GSocketConnection *connection); void grd_session_vnc_queue_resize_framebuffer (GrdSessionVnc *session_vnc, int width, int height); void grd_session_vnc_take_buffer (GrdSessionVnc *session_vnc, void *data); void grd_session_vnc_set_cursor (GrdSessionVnc *session_vnc, rfbCursorPtr rfb_cursor); void grd_session_vnc_move_cursor (GrdSessionVnc *session_vnc, int x, int y); int grd_session_vnc_get_framebuffer_stride (GrdSessionVnc *session_vnc); #endif /* GRD_SESSION_VNC_H */ 07070100000017000081A4000003E800000064000000015E7474AE00004B44000000000000000000000000000000000000002D00000000gnome-remote-desktop-0.1.8/src/grd-session.c/* * Copyright (C) 2015 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by: * Jonas Ådahl <jadahl@gmail.com> */ #include "config.h" #include "grd-session.h" #include <glib-object.h> #include "grd-dbus-remote-desktop.h" #include "grd-context.h" #include "grd-private.h" #include "grd-stream.h" enum { PROP_0, PROP_CONTEXT, }; enum { STOPPED, LAST_SIGNAL }; static guint signals[LAST_SIGNAL]; typedef enum _GrdScreenCastCursorMode { GRD_SCREEN_CAST_CURSOR_MODE_HIDDEN = 0, GRD_SCREEN_CAST_CURSOR_MODE_EMBEDDED = 1, GRD_SCREEN_CAST_CURSOR_MODE_METADATA = 2, } GrdScreenCastCursorMode; typedef struct _GrdSessionPrivate { GrdContext *context; GrdDBusRemoteDesktopSession *remote_desktop_session; GrdDBusScreenCastSession *screen_cast_session; GrdStream *stream; GCancellable *cancellable; gboolean started; } GrdSessionPrivate; G_DEFINE_TYPE_WITH_PRIVATE (GrdSession, grd_session, G_TYPE_OBJECT); GrdContext * grd_session_get_context (GrdSession *session) { GrdSessionPrivate *priv = grd_session_get_instance_private (session); return priv->context; } void grd_session_stop (GrdSession *session) { GrdSessionPrivate *priv = grd_session_get_instance_private (session); GRD_SESSION_GET_CLASS (session)->stop (session); if (priv->remote_desktop_session && priv->started) { GrdDBusRemoteDesktopSession *proxy = priv->remote_desktop_session; GError *error = NULL; if (!grd_dbus_remote_desktop_session_call_stop_sync (proxy, NULL, &error)) { g_warning ("Failed to stop: %s\n", error->message); g_error_free (error); } } g_clear_object (&priv->remote_desktop_session); g_clear_object (&priv->screen_cast_session); g_signal_emit (session, signals[STOPPED], 0); } void grd_session_notify_keyboard_keysym (GrdSession *session, uint32_t keysym, GrdKeyState state) { GrdSessionPrivate *priv = grd_session_get_instance_private (session); GrdDBusRemoteDesktopSession *session_proxy = priv->remote_desktop_session; grd_dbus_remote_desktop_session_call_notify_keyboard_keysym (session_proxy, keysym, state, NULL, NULL, NULL); } void grd_session_notify_pointer_button (GrdSession *session, int32_t button, GrdButtonState state) { GrdSessionPrivate *priv = grd_session_get_instance_private (session); GrdDBusRemoteDesktopSession *session_proxy = priv->remote_desktop_session; grd_dbus_remote_desktop_session_call_notify_pointer_button (session_proxy, button, state, NULL, NULL, NULL); } void grd_session_notify_pointer_axis_discrete (GrdSession *session, GrdPointerAxis axis, int steps) { GrdSessionPrivate *priv = grd_session_get_instance_private (session); GrdDBusRemoteDesktopSession *session_proxy = priv->remote_desktop_session; grd_dbus_remote_desktop_session_call_notify_pointer_axis_discrete ( session_proxy, axis, steps, NULL, NULL, NULL); } void grd_session_notify_pointer_motion_absolute (GrdSession *session, double x, double y) { GrdSessionPrivate *priv = grd_session_get_instance_private (session); const char *stream_path; stream_path = grd_stream_get_object_path (priv->stream); grd_dbus_remote_desktop_session_call_notify_pointer_motion_absolute ( priv->remote_desktop_session, stream_path, x, y, NULL, NULL, NULL); } static void on_stream_ready (GrdStream *stream, GrdSession *session) { GRD_SESSION_GET_CLASS (session)->stream_ready (session, stream); } static void on_stream_closed (GrdStream *stream, GrdSession *session) { grd_session_stop (session); } static void on_session_start_finished (GObject *object, GAsyncResult *result, gpointer user_data) { GrdSession *session = user_data; GrdSessionPrivate *priv = grd_session_get_instance_private (session); GrdDBusRemoteDesktopSession *proxy = priv->remote_desktop_session; GError *error = NULL; if (!grd_dbus_remote_desktop_session_call_start_finish (proxy, result, &error)) { g_warning ("Failed to start session: %s", error->message); g_error_free (error); grd_session_stop (session); return; } priv->started = TRUE; } static void start_session (GrdSession *session) { GrdSessionPrivate *priv = grd_session_get_instance_private (session); GrdDBusRemoteDesktopSession *proxy = priv->remote_desktop_session; grd_dbus_remote_desktop_session_call_start (proxy, priv->cancellable, on_session_start_finished, session); } static void on_screen_cast_stream_proxy_acquired (GObject *object, GAsyncResult *result, gpointer user_data) { GrdSession *session = user_data; GrdSessionPrivate *priv = grd_session_get_instance_private (session); GrdDBusScreenCastStream *stream_proxy; GError *error = NULL; GrdStream *stream; stream_proxy = grd_dbus_screen_cast_stream_proxy_new_finish (result, &error); if (!stream_proxy) { g_warning ("Failed to acquire stream proxy: %s", error->message); g_error_free (error); grd_session_stop (session); return; } stream = grd_stream_new (priv->context, stream_proxy); g_signal_connect (stream, "ready", G_CALLBACK (on_stream_ready), session); g_signal_connect (stream, "closed", G_CALLBACK (on_stream_closed), session); priv->stream = stream; start_session (session); } static void on_record_monitor_finished (GObject *object, GAsyncResult *result, gpointer user_data) { GrdSession *session = user_data; GrdSessionPrivate *priv = grd_session_get_instance_private (session); GrdDBusScreenCastSession *proxy = priv->screen_cast_session; g_autofree char *stream_path = NULL; GError *error = NULL; GDBusConnection *connection; if (!grd_dbus_screen_cast_session_call_record_monitor_finish (proxy, &stream_path, result, &error)) { g_warning ("Failed to record monitor: %s", error->message); g_error_free (error); grd_session_stop (session); return; } connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (proxy)); grd_dbus_screen_cast_stream_proxy_new (connection, G_DBUS_PROXY_FLAGS_NONE, MUTTER_SCREEN_CAST_BUS_NAME, stream_path, priv->cancellable, on_screen_cast_stream_proxy_acquired, session); } static void on_screen_cast_session_proxy_acquired (GObject *object, GAsyncResult *result, gpointer user_data) { GrdSession *session = user_data; GrdSessionPrivate *priv = grd_session_get_instance_private (session); GrdDBusScreenCastSession *session_proxy; GVariantBuilder properties_builder; GError *error = NULL; session_proxy = grd_dbus_screen_cast_session_proxy_new_finish (result, &error); if (!session_proxy) { g_warning ("Failed to acquire screen cast session proxy: %s\n", error->message); g_error_free (error); grd_session_stop (session); return; } priv->screen_cast_session = session_proxy; g_variant_builder_init (&properties_builder, G_VARIANT_TYPE ("a{sv}")); g_variant_builder_add (&properties_builder, "{sv}", "cursor-mode", g_variant_new_uint32 (GRD_SCREEN_CAST_CURSOR_MODE_METADATA)); /* TODO: Support something other than primary monitor */ grd_dbus_screen_cast_session_call_record_monitor (session_proxy, "", g_variant_builder_end (&properties_builder), priv->cancellable, on_record_monitor_finished, session); } static void on_screen_cast_session_created (GObject *source_object, GAsyncResult *res, gpointer user_data) { GrdSession *session = user_data; GrdSessionPrivate *priv = grd_session_get_instance_private (session); GrdDBusScreenCast *screen_cast_proxy; g_autofree char *session_path = NULL; GError *error = NULL; GDBusConnection *connection; screen_cast_proxy = grd_context_get_screen_cast_proxy (priv->context); if (!grd_dbus_screen_cast_call_create_session_finish (screen_cast_proxy, &session_path, res, &error)) { g_warning ("Failed to start screen cast session: %s\n", error->message); g_error_free (error); grd_session_stop (session); return; } connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (screen_cast_proxy)); grd_dbus_screen_cast_session_proxy_new (connection, G_DBUS_PROXY_FLAGS_NONE, MUTTER_SCREEN_CAST_BUS_NAME, session_path, priv->cancellable, on_screen_cast_session_proxy_acquired, session); } static void on_remote_desktop_session_closed (GrdDBusRemoteDesktopSession *session_proxy, GrdSession *session) { GrdSessionPrivate *priv = grd_session_get_instance_private (session); g_clear_object (&priv->remote_desktop_session); g_clear_object (&priv->screen_cast_session); grd_session_stop (session); } static void on_remote_desktop_session_proxy_acquired (GObject *object, GAsyncResult *result, gpointer user_data) { GrdSession *session = user_data; GrdSessionPrivate *priv = grd_session_get_instance_private (session); GrdDBusRemoteDesktopSession *session_proxy; GError *error = NULL; const char *remote_desktop_session_id; GrdDBusScreenCast *screen_cast_proxy; GVariantBuilder properties_builder; GVariant *properties_variant; session_proxy = grd_dbus_remote_desktop_session_proxy_new_finish (result, &error); if (!session_proxy) { g_warning ("Failed to acquire remote desktop session proxy: %s\n", error->message); g_error_free (error); grd_session_stop (session); return; } g_signal_connect (session_proxy, "closed", G_CALLBACK (on_remote_desktop_session_closed), session); priv->remote_desktop_session = session_proxy; remote_desktop_session_id = grd_dbus_remote_desktop_session_get_session_id (session_proxy); g_variant_builder_init (&properties_builder, G_VARIANT_TYPE ("a{sv}")); g_variant_builder_add (&properties_builder, "{sv}", "remote-desktop-session-id", g_variant_new_string (remote_desktop_session_id)); g_variant_builder_add (&properties_builder, "{sv}", "disable-animations", g_variant_new_boolean (TRUE)); properties_variant = g_variant_builder_end (&properties_builder); screen_cast_proxy = grd_context_get_screen_cast_proxy (priv->context); grd_dbus_screen_cast_call_create_session (screen_cast_proxy, properties_variant, priv->cancellable, on_screen_cast_session_created, session); } static void on_remote_desktop_session_created (GObject *source_object, GAsyncResult *res, gpointer user_data) { GrdSession *session = user_data; GrdSessionPrivate *priv = grd_session_get_instance_private (session); GrdDBusRemoteDesktop *remote_desktop_proxy; g_autofree char *session_path = NULL; GDBusConnection *connection; GError *error = NULL; remote_desktop_proxy = grd_context_get_remote_desktop_proxy (priv->context); if (!grd_dbus_remote_desktop_call_create_session_finish (remote_desktop_proxy, &session_path, res, &error)) { g_warning ("Failed to start remote desktop session: %s\n", error->message); g_error_free (error); grd_session_stop (session); return; } connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (remote_desktop_proxy)); grd_dbus_remote_desktop_session_proxy_new (connection, G_DBUS_PROXY_FLAGS_NONE, MUTTER_REMOTE_DESKTOP_BUS_NAME, session_path, priv->cancellable, on_remote_desktop_session_proxy_acquired, session); } void grd_session_start (GrdSession *session) { GrdSessionPrivate *priv = grd_session_get_instance_private (session); GrdDBusRemoteDesktop *remote_desktop_proxy; priv->cancellable = g_cancellable_new (); remote_desktop_proxy = grd_context_get_remote_desktop_proxy (priv->context); grd_dbus_remote_desktop_call_create_session (remote_desktop_proxy, priv->cancellable, on_remote_desktop_session_created, session); } static void grd_session_dispose (GObject *object) { GrdSession *session = GRD_SESSION (object); GrdSessionPrivate *priv = grd_session_get_instance_private (session); g_clear_object (&priv->stream); G_OBJECT_CLASS (grd_session_parent_class)->dispose (object); } static void grd_session_finalize (GObject *object) { GrdSession *session = GRD_SESSION (object); GrdSessionPrivate *priv = grd_session_get_instance_private (session); g_assert (!priv->remote_desktop_session); if (priv->cancellable) g_cancellable_cancel (priv->cancellable); g_clear_object (&priv->cancellable); G_OBJECT_CLASS (grd_session_parent_class)->finalize (object); } static void grd_session_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GrdSession *session = GRD_SESSION (object); GrdSessionPrivate *priv = grd_session_get_instance_private (session); switch (prop_id) { case PROP_CONTEXT: priv->context = g_value_get_object (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void grd_session_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GrdSession *session = GRD_SESSION (object); GrdSessionPrivate *priv = grd_session_get_instance_private (session); switch (prop_id) { case PROP_CONTEXT: g_value_set_object (value, priv->context); default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void grd_session_init (GrdSession *session) { } static void grd_session_class_init (GrdSessionClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = grd_session_dispose; object_class->finalize = grd_session_finalize; object_class->set_property = grd_session_set_property; object_class->get_property = grd_session_get_property; g_object_class_install_property (object_class, PROP_CONTEXT, g_param_spec_object ("context", "GrdContext", "The GrdContext instance", GRD_TYPE_CONTEXT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); signals[STOPPED] = g_signal_new ("stopped", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0); } 07070100000018000081A4000003E800000064000000015E7474AE000009DD000000000000000000000000000000000000002D00000000gnome-remote-desktop-0.1.8/src/grd-session.h/* * Copyright (C) 2015 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by: * Jonas Ådahl <jadahl@gmail.com> */ #ifndef GRD_SESSION_H #define GRD_SESSION_H #include <glib-object.h> #include <stdint.h> #include "grd-types.h" #define GRD_TYPE_SESSION (grd_session_get_type ()) G_DECLARE_DERIVABLE_TYPE (GrdSession, grd_session, GRD, SESSION, GObject); typedef enum _GrdKeyState { GRD_KEY_STATE_RELEASED, GRD_KEY_STATE_PRESSED } GrdKeyState; typedef enum _GrdButtonState { GRD_BUTTON_STATE_RELEASED, GRD_BUTTON_STATE_PRESSED } GrdButtonState; typedef enum _GrdPointerAxis { GRD_POINTER_AXIS_VERTICAL, GRD_POINTER_AXIS_HORIZONTAL } GrdPointerAxis; struct _GrdSessionClass { GObjectClass parent_class; void (*stream_ready) (GrdSession *session, GrdStream *stream); void (*stop) (GrdSession *session); }; GrdContext *grd_session_get_context (GrdSession *session); void grd_session_notify_keyboard_keysym (GrdSession *session, uint32_t keysym, GrdKeyState state); void grd_session_notify_pointer_button (GrdSession *session, int32_t button, GrdButtonState state); void grd_session_notify_pointer_axis_discrete (GrdSession *session, GrdPointerAxis axis, int steps); void grd_session_notify_pointer_motion_absolute (GrdSession *session, double x, double y); void grd_session_start (GrdSession *session); void grd_session_stop (GrdSession *session); #endif /* GRD_SESSION_H */ 07070100000019000081A4000003E800000064000000015E7474AE000013B2000000000000000000000000000000000000002E00000000gnome-remote-desktop-0.1.8/src/grd-settings.c/* * Copyright (C) 2018 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * */ #include "config.h" #include "grd-settings.h" #include <gio/gio.h> #include <string.h> #define GRD_VNC_SCHEMA_ID "org.gnome.desktop.remote-desktop.vnc" #define GRD_VNC_SERVER_PORT 5900 enum { VNC_VIEW_ONLY_CHANGED, VNC_AUTH_METHOD_CHANGED, VNC_ENCRYPTION_CHANGED, N_SIGNALS }; static guint signals[N_SIGNALS]; struct _GrdSettings { GObject parent; struct { GSettings *settings; gboolean view_only; GrdVncAuthMethod auth_method; int port; } vnc; }; G_DEFINE_TYPE (GrdSettings, grd_settings, G_TYPE_OBJECT) const SecretSchema * grd_vnc_password_get_schema (void) { static const SecretSchema grd_vnc_password_schema = { .name = "org.gnome.RemoteDesktop.VncPassword", .flags = SECRET_SCHEMA_NONE, .attributes = { { "password", SECRET_SCHEMA_ATTRIBUTE_STRING }, { "NULL", 0 }, }, }; return &grd_vnc_password_schema; } int grd_settings_get_vnc_port (GrdSettings *settings) { return settings->vnc.port; } void grd_settings_override_vnc_port (GrdSettings *settings, int port) { settings->vnc.port = port; } char * grd_settings_get_vnc_password (GrdSettings *settings, GError **error) { const char *test_password_override; char *password; test_password_override = g_getenv ("GNOME_REMOTE_DESKTOP_TEST_VNC_PASSWORD"); if (test_password_override) return g_strdup (test_password_override); password = secret_password_lookup_sync (GRD_VNC_PASSWORD_SCHEMA, NULL, error, NULL); if (!password) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Password not set"); return NULL; } return password; } gboolean grd_settings_get_vnc_view_only (GrdSettings *settings) { return settings->vnc.view_only; } GrdVncAuthMethod grd_settings_get_vnc_auth_method (GrdSettings *settings) { if (g_getenv ("GNOME_REMOTE_DESKTOP_TEST_VNC_PASSWORD")) return GRD_VNC_AUTH_METHOD_PASSWORD; else return settings->vnc.auth_method; } static void update_vnc_view_only (GrdSettings *settings) { settings->vnc.view_only = g_settings_get_boolean (settings->vnc.settings, "view-only"); } static void update_vnc_auth_method (GrdSettings *settings) { settings->vnc.auth_method = g_settings_get_enum (settings->vnc.settings, "auth-method"); } static void on_vnc_settings_changed (GSettings *vnc_settings, const char *key, GrdSettings *settings) { if (strcmp (key, "view-only") == 0) { update_vnc_view_only (settings); g_signal_emit (settings, signals[VNC_VIEW_ONLY_CHANGED], 0); } else if (strcmp (key, "auth-method") == 0) { update_vnc_auth_method (settings); g_signal_emit (settings, signals[VNC_AUTH_METHOD_CHANGED], 0); } } static void grd_settings_finalize (GObject *object) { GrdSettings *settings = GRD_SETTINGS (object); g_clear_object (&settings->vnc.settings); G_OBJECT_CLASS (grd_settings_parent_class)->finalize (object); } static void grd_settings_init (GrdSettings *settings) { settings->vnc.settings = g_settings_new (GRD_VNC_SCHEMA_ID); g_signal_connect (settings->vnc.settings, "changed", G_CALLBACK (on_vnc_settings_changed), settings); update_vnc_view_only (settings); update_vnc_auth_method (settings); settings->vnc.port = GRD_VNC_SERVER_PORT; } static void grd_settings_class_init (GrdSettingsClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = grd_settings_finalize; signals[VNC_VIEW_ONLY_CHANGED] = g_signal_new ("vnc-view-only-changed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0); signals[VNC_AUTH_METHOD_CHANGED] = g_signal_new ("vnc-auth-method-changed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0); } 0707010000001A000081A4000003E800000064000000015E7474AE00000661000000000000000000000000000000000000002E00000000gnome-remote-desktop-0.1.8/src/grd-settings.h/* * Copyright (C) 2018 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * */ #ifndef GRD_SETTINGS_H #define GRD_SETTINGS_H #include <glib-object.h> #include <libsecret/secret.h> #include "grd-enums.h" #define GRD_TYPE_SETTINGS (grd_settings_get_type ()) G_DECLARE_FINAL_TYPE (GrdSettings, grd_settings, GRD, SETTINGS, GObject) const SecretSchema * cc_grd_vnc_password_get_schema (void); #define GRD_VNC_PASSWORD_SCHEMA grd_vnc_password_get_schema () int grd_settings_get_vnc_port (GrdSettings *settings); void grd_settings_override_vnc_port (GrdSettings *settings, int port); char * grd_settings_get_vnc_password (GrdSettings *settings, GError **error); gboolean grd_settings_get_vnc_view_only (GrdSettings *settings); GrdVncAuthMethod grd_settings_get_vnc_auth_method (GrdSettings *settings); #endif /* GRD_SETTINGS_H */ 0707010000001B000081A4000003E800000064000000015E7474AE00000D49000000000000000000000000000000000000002C00000000gnome-remote-desktop-0.1.8/src/grd-stream.c/* * Copyright (C) 2017 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * */ #include "config.h" #include "grd-stream.h" #include "grd-context.h" enum { READY, CLOSED, N_SIGNALS }; static guint signals[N_SIGNALS]; typedef struct _GrdStreamPrivate { GrdContext *context; uint32_t pipewire_node_id; GrdDBusScreenCastStream *proxy; } GrdStreamPrivate; G_DEFINE_TYPE_WITH_PRIVATE (GrdStream, grd_stream, G_TYPE_OBJECT) uint32_t grd_stream_get_pipewire_node_id (GrdStream *stream) { GrdStreamPrivate *priv = grd_stream_get_instance_private (stream); return priv->pipewire_node_id; } const char * grd_stream_get_object_path (GrdStream *stream) { GrdStreamPrivate *priv = grd_stream_get_instance_private (stream); return g_dbus_proxy_get_object_path (G_DBUS_PROXY (priv->proxy)); } static void on_pipewire_stream_added (GrdDBusScreenCastStream *proxy, unsigned int node_id, GrdStream *stream) { GrdStreamPrivate *priv = grd_stream_get_instance_private (stream); priv->pipewire_node_id = (uint32_t) node_id; g_signal_emit (stream, signals[READY], 0); } GrdStream * grd_stream_new (GrdContext *context, GrdDBusScreenCastStream *proxy) { GrdStream *stream; GrdStreamPrivate *priv; stream = g_object_new (GRD_TYPE_STREAM, NULL); priv = grd_stream_get_instance_private (stream); priv->context = context; priv->proxy = proxy; g_signal_connect (proxy, "pipewire-stream-added", G_CALLBACK (on_pipewire_stream_added), stream); return stream; } static void grd_stream_finalize (GObject *object) { GrdStream *stream = GRD_STREAM (object); GrdStreamPrivate *priv = grd_stream_get_instance_private (stream); g_clear_object (&priv->proxy); G_OBJECT_CLASS (grd_stream_parent_class)->finalize (object); } static void grd_stream_init (GrdStream *stream) { } static void grd_stream_class_init (GrdStreamClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = grd_stream_finalize; signals[READY] = g_signal_new ("ready", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0); signals[CLOSED] = g_signal_new ("closed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0); } 0707010000001C000081A4000003E800000064000000015E7474AE00000557000000000000000000000000000000000000002C00000000gnome-remote-desktop-0.1.8/src/grd-stream.h/* * Copyright (C) 2017 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * */ #ifndef GRD_STREAM_H #define GRD_STREAM_H #include <glib-object.h> #include <stdint.h> #include "grd-dbus-screen-cast.h" #include "grd-types.h" #define GRD_TYPE_STREAM (grd_stream_get_type ()) G_DECLARE_DERIVABLE_TYPE (GrdStream, grd_stream, GRD, STREAM, GObject) struct _GrdStreamClass { GObjectClass parent_class; }; uint32_t grd_stream_get_pipewire_node_id (GrdStream *stream); const char * grd_stream_get_object_path (GrdStream *stream); GrdStream * grd_stream_new (GrdContext *context, GrdDBusScreenCastStream *proxy); #endif /* GRD_STREAM_H */ 0707010000001D000081A4000003E800000064000000015E7474AE00000509000000000000000000000000000000000000002B00000000gnome-remote-desktop-0.1.8/src/grd-types.h/* * Copyright (C) 2015 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by: * Jonas Ådahl <jadahl@gmail.com> */ #ifndef GRD_TYPES_H #define GRD_TYPES_H typedef struct _GrdContext GrdContext; typedef struct _GrdSession GrdSession; typedef struct _GrdSessionVnc GrdSessionVnc; typedef struct _GrdStream GrdStream; typedef struct _GrdPipeWireStream GrdPipeWireStream; typedef struct _GrdPipeWireStreamMonitor GrdPipeWireStreamMonitor; typedef struct _GrdVncServer GrdVncServer; typedef enum _GrdPixelFormat { GRD_PIXEL_FORMAT_RGBA8888, } GrdPixelFormat; #endif /* GRD_TYPES_H */ 0707010000001E000081A4000003E800000064000000015E7474AE00000C6C000000000000000000000000000000000000003000000000gnome-remote-desktop-0.1.8/src/grd-vnc-cursor.c/* * Copyright (C) 2018 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * */ #include "config.h" #include "grd-vnc-cursor.h" #include <glib.h> #include <stdint.h> static void get_pixel_components (uint32_t pixel, GrdPixelFormat format, uint8_t *a, uint8_t *r, uint8_t *g, uint8_t *b) { g_assert (format == GRD_PIXEL_FORMAT_RGBA8888); *a = (pixel & 0xff000000) >> 24; *b = (pixel & 0xff0000) >> 16; *g = (pixel & 0xff00) >> 8; *r = pixel & 0xff; } static gboolean is_practically_black (uint8_t r, uint8_t g, uint8_t b) { if (r <= 0x62 && g <= 0x62 && b <= 0x62) return TRUE; else return FALSE; } static gboolean is_practically_opaque (uint8_t a) { return a > 0xe0; } rfbCursorPtr grd_vnc_create_cursor (int width, int height, int stride, GrdPixelFormat format, uint8_t *buf) { g_autofree char *cursor = NULL; g_autofree char *mask = NULL; int y; g_return_val_if_fail (format == GRD_PIXEL_FORMAT_RGBA8888, NULL); cursor = g_new0 (char, width * height); mask = g_new0 (char, width * height); for (y = 0; y < height; y++) { uint32_t *pixel_row; int x; pixel_row = (uint32_t *) &buf[y * stride]; for (x = 0; x < width; x++) { uint32_t pixel = pixel_row[x]; uint8_t a, r, g, b; get_pixel_components (pixel, format, &a, &r, &g, &b); if (is_practically_opaque (a)) { if (is_practically_black (r, g, b)) cursor[y * width + x] = ' '; else cursor[y * width + x] = 'x'; mask[y * width + x] = 'x'; } else { cursor[y * width + x] = ' '; mask[y * width + x] = ' '; } } } return rfbMakeXCursor (width, height, cursor, mask); } rfbCursorPtr grd_vnc_create_empty_cursor (int width, int height) { g_autofree char *cursor = NULL; cursor = g_new0 (char, width * height); memset (cursor, ' ', width * height); return rfbMakeXCursor (width, height, cursor, cursor); } 0707010000001F000081A4000003E800000064000000015E7474AE00000514000000000000000000000000000000000000003000000000gnome-remote-desktop-0.1.8/src/grd-vnc-cursor.h/* * Copyright (C) 2018 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * */ #ifndef GRD_VNC_CURSOR_H #define GRD_VNC_CURSOR_H #include <rfb/rfb.h> #include "grd-types.h" rfbCursorPtr grd_vnc_create_cursor (int width, int height, int stride, GrdPixelFormat format, uint8_t *buf); rfbCursorPtr grd_vnc_create_empty_cursor (int width, int height); #endif /* GRD_VNC_CURSOR_H */ 07070100000020000081A4000003E800000064000000015E7474AE000048B7000000000000000000000000000000000000003900000000gnome-remote-desktop-0.1.8/src/grd-vnc-pipewire-stream.c/* * Copyright (C) 2018 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * */ #include "config.h" #include "grd-vnc-pipewire-stream.h" #include <linux/dma-buf.h> #include <pipewire/pipewire.h> #include <spa/param/props.h> #include <spa/param/format-utils.h> #include <spa/param/video/format-utils.h> #include <spa/utils/result.h> #include <sys/ioctl.h> #include <sys/mman.h> #include <sys/syscall.h> #include "grd-vnc-cursor.h" enum { CLOSED, N_SIGNALS }; guint signals[N_SIGNALS]; typedef struct _GrdPipeWireSource { GSource base; struct pw_loop *pipewire_loop; } GrdPipeWireSource; typedef struct _GrdVncFrame { void *data; rfbCursorPtr rfb_cursor; gboolean cursor_moved; int cursor_x; int cursor_y; } GrdVncFrame; struct _GrdVncPipeWireStream { GObject parent; GrdSessionVnc *session; GSource *pipewire_source; struct pw_context *pipewire_context; struct pw_core *pipewire_core; struct spa_hook pipewire_core_listener; GMutex frame_mutex; GrdVncFrame *pending_frame; struct pw_stream *pipewire_stream; struct spa_hook pipewire_stream_listener; uint32_t src_node_id; struct spa_video_info_raw spa_format; }; G_DEFINE_TYPE (GrdVncPipeWireStream, grd_vnc_pipewire_stream, G_TYPE_OBJECT) #define CURSOR_META_SIZE(width, height) \ (sizeof(struct spa_meta_cursor) + \ sizeof(struct spa_meta_bitmap) + width * height * 4) static gboolean pipewire_loop_source_prepare (GSource *base, int *timeout) { *timeout = -1; return FALSE; } static gboolean pipewire_loop_source_dispatch (GSource *source, GSourceFunc callback, gpointer user_data) { GrdPipeWireSource *pipewire_source = (GrdPipeWireSource *) source; int result; result = pw_loop_iterate (pipewire_source->pipewire_loop, 0); if (result < 0) g_warning ("pipewire_loop_iterate failed: %s", spa_strerror (result)); return TRUE; } static void pipewire_loop_source_finalize (GSource *source) { GrdPipeWireSource *pipewire_source = (GrdPipeWireSource *) source; pw_loop_leave (pipewire_source->pipewire_loop); pw_loop_destroy (pipewire_source->pipewire_loop); } static GSourceFuncs pipewire_source_funcs = { pipewire_loop_source_prepare, NULL, pipewire_loop_source_dispatch, pipewire_loop_source_finalize }; static GrdPipeWireSource * create_pipewire_source (void) { GrdPipeWireSource *pipewire_source; pipewire_source = (GrdPipeWireSource *) g_source_new (&pipewire_source_funcs, sizeof (GrdPipeWireSource)); pipewire_source->pipewire_loop = pw_loop_new (NULL); if (!pipewire_source->pipewire_loop) { g_source_destroy ((GSource *) pipewire_source); return NULL; } g_source_add_unix_fd (&pipewire_source->base, pw_loop_get_fd (pipewire_source->pipewire_loop), G_IO_IN | G_IO_ERR); pw_loop_enter (pipewire_source->pipewire_loop); g_source_attach (&pipewire_source->base, NULL); return pipewire_source; } static void on_stream_state_changed (void *user_data, enum pw_stream_state old, enum pw_stream_state state, const char *error) { g_debug ("Pipewire stream state changed from %s to %s", pw_stream_state_as_string (old), pw_stream_state_as_string (state)); switch (state) { case PW_STREAM_STATE_ERROR: g_warning ("PipeWire stream error: %s", error); break; case PW_STREAM_STATE_PAUSED: case PW_STREAM_STATE_STREAMING: case PW_STREAM_STATE_UNCONNECTED: case PW_STREAM_STATE_CONNECTING: break; } } static void on_stream_param_changed (void *user_data, uint32_t id, const struct spa_pod *format) { GrdVncPipeWireStream *stream = GRD_VNC_PIPEWIRE_STREAM (user_data); uint8_t params_buffer[1024]; struct spa_pod_builder pod_builder; int width; int height; int stride; int size; const struct spa_pod *params[3]; if (!format || id != SPA_PARAM_Format) return; spa_format_video_raw_parse (format, &stream->spa_format); pod_builder = SPA_POD_BUILDER_INIT (params_buffer, sizeof (params_buffer)); width = stream->spa_format.size.width; height = stream->spa_format.size.height; grd_session_vnc_queue_resize_framebuffer (stream->session, width, height); stride = grd_session_vnc_get_framebuffer_stride (stream->session); size = stride * height; params[0] = spa_pod_builder_add_object ( &pod_builder, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, SPA_PARAM_BUFFERS_size, SPA_POD_Int (size), SPA_PARAM_BUFFERS_stride, SPA_POD_Int (stride), SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int (8, 1, 8), 0); params[1] = spa_pod_builder_add_object ( &pod_builder, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, SPA_PARAM_META_type, SPA_POD_Id (SPA_META_Header), SPA_PARAM_META_size, SPA_POD_Int (sizeof (struct spa_meta_header)), 0); params[2] = spa_pod_builder_add_object( &pod_builder, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, SPA_PARAM_META_type, SPA_POD_Id (SPA_META_Cursor), SPA_PARAM_META_size, SPA_POD_CHOICE_RANGE_Int (CURSOR_META_SIZE (64,64), CURSOR_META_SIZE (1,1), CURSOR_META_SIZE (256,256)), 0); pw_stream_update_params (stream->pipewire_stream, params, G_N_ELEMENTS (params)); } static gboolean spa_pixel_format_to_grd_pixel_format (uint32_t spa_format, GrdPixelFormat *out_format) { if (spa_format == SPA_VIDEO_FORMAT_RGBA) *out_format = GRD_PIXEL_FORMAT_RGBA8888; else return FALSE; return TRUE; } static void sync_dma_buf (int fd, uint64_t start_or_end) { struct dma_buf_sync sync = { 0 }; sync.flags = start_or_end | DMA_BUF_SYNC_READ; while (TRUE) { int ret; ret = ioctl (fd, DMA_BUF_IOCTL_SYNC, &sync); if (ret == -1 && errno == EINTR) { continue; } else if (ret == -1) { g_warning ("Failed to synchronize DMA buffer: %s", g_strerror (errno)); break; } else { break; } } } static int do_render (struct spa_loop *loop, bool async, uint32_t seq, const void *data, size_t size, void *user_data) { GrdVncPipeWireStream *stream = GRD_VNC_PIPEWIRE_STREAM (user_data); GrdVncFrame *frame; g_mutex_lock (&stream->frame_mutex); frame = g_steal_pointer (&stream->pending_frame); g_mutex_unlock (&stream->frame_mutex); if (!frame) return 0; if (frame->rfb_cursor) grd_session_vnc_set_cursor (stream->session, frame->rfb_cursor); if (frame->cursor_moved) { grd_session_vnc_move_cursor (stream->session, frame->cursor_x, frame->cursor_y); } if (frame->data) grd_session_vnc_take_buffer (stream->session, frame->data); g_free (frame); return 0; } static GrdVncFrame * process_buffer (GrdVncPipeWireStream *stream, struct spa_buffer *buffer) { size_t size; uint8_t *map; void *src_data; struct spa_meta_cursor *spa_meta_cursor; g_autofree GrdVncFrame *frame = NULL; frame = g_new0 (GrdVncFrame, 1); if (buffer->datas[0].chunk->size == 0) { size = 0; map = NULL; src_data = NULL; } else if (buffer->datas[0].type == SPA_DATA_MemFd) { size = buffer->datas[0].maxsize + buffer->datas[0].mapoffset; map = mmap (NULL, size, PROT_READ, MAP_PRIVATE, buffer->datas[0].fd, 0); src_data = SPA_MEMBER (map, buffer->datas[0].mapoffset, uint8_t); } else if (buffer->datas[0].type == SPA_DATA_DmaBuf) { int fd; fd = buffer->datas[0].fd; size = buffer->datas[0].maxsize + buffer->datas[0].mapoffset; map = mmap (NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); sync_dma_buf (fd, DMA_BUF_SYNC_START); src_data = SPA_MEMBER (map, buffer->datas[0].mapoffset, uint8_t); } else if (buffer->datas[0].type == SPA_DATA_MemPtr) { size = buffer->datas[0].maxsize + buffer->datas[0].mapoffset; map = NULL; src_data = buffer->datas[0].data; } else { return NULL; } frame->data = g_memdup (src_data, buffer->datas[0].maxsize); if (map) { if (buffer->datas[0].type == SPA_DATA_DmaBuf) sync_dma_buf (buffer->datas[0].fd, DMA_BUF_SYNC_END); munmap (map, size); } spa_meta_cursor = spa_buffer_find_meta_data (buffer, SPA_META_Cursor, sizeof *spa_meta_cursor); if (spa_meta_cursor && spa_meta_cursor_is_valid (spa_meta_cursor)) { struct spa_meta_bitmap *spa_meta_bitmap; GrdPixelFormat format; if (spa_meta_cursor->bitmap_offset) { spa_meta_bitmap = SPA_MEMBER (spa_meta_cursor, spa_meta_cursor->bitmap_offset, struct spa_meta_bitmap); } else { spa_meta_bitmap = NULL; } if (spa_meta_bitmap && spa_meta_bitmap->size.width > 0 && spa_meta_bitmap->size.height > 0 && spa_pixel_format_to_grd_pixel_format (spa_meta_bitmap->format, &format)) { uint8_t *buf; rfbCursorPtr rfb_cursor; buf = SPA_MEMBER (spa_meta_bitmap, spa_meta_bitmap->offset, uint8_t); rfb_cursor = grd_vnc_create_cursor (spa_meta_bitmap->size.width, spa_meta_bitmap->size.height, spa_meta_bitmap->stride, format, buf); rfb_cursor->xhot = spa_meta_cursor->hotspot.x; rfb_cursor->yhot = spa_meta_cursor->hotspot.y; frame->rfb_cursor = rfb_cursor; } else if (spa_meta_bitmap) { frame->rfb_cursor = grd_vnc_create_empty_cursor (1, 1); } frame->cursor_moved = TRUE; frame->cursor_x = spa_meta_cursor->position.x; frame->cursor_y = spa_meta_cursor->position.y; } return g_steal_pointer (&frame); } static void on_stream_process (void *user_data) { GrdVncPipeWireStream *stream = GRD_VNC_PIPEWIRE_STREAM (user_data); GrdPipeWireSource *pipewire_source = (GrdPipeWireSource *) stream->pipewire_source; struct pw_buffer *next_buffer; struct pw_buffer *buffer = NULL; GrdVncFrame *frame; next_buffer = pw_stream_dequeue_buffer (stream->pipewire_stream); while (next_buffer) { buffer = next_buffer; next_buffer = pw_stream_dequeue_buffer (stream->pipewire_stream); if (next_buffer) pw_stream_queue_buffer (stream->pipewire_stream, buffer); } if (!buffer) return; frame = process_buffer (stream, buffer->buffer); g_assert (frame); g_mutex_lock (&stream->frame_mutex); if (stream->pending_frame) { g_free (stream->pending_frame->data); g_clear_pointer (&stream->pending_frame, g_free); } stream->pending_frame = frame; g_mutex_unlock (&stream->frame_mutex); pw_stream_queue_buffer (stream->pipewire_stream, buffer); pw_loop_invoke (pipewire_source->pipewire_loop, do_render, SPA_ID_INVALID, NULL, 0, false, stream); } static const struct pw_stream_events stream_events = { PW_VERSION_STREAM_EVENTS, .state_changed = on_stream_state_changed, .param_changed = on_stream_param_changed, .process = on_stream_process, }; static gboolean connect_to_stream (GrdVncPipeWireStream *stream, GError **error) { struct pw_stream *pipewire_stream; uint8_t params_buffer[1024]; struct spa_pod_builder pod_builder; struct spa_rectangle min_rect; struct spa_rectangle max_rect; struct spa_fraction min_framerate; struct spa_fraction max_framerate; const struct spa_pod *params[2]; int ret; pipewire_stream = pw_stream_new (stream->pipewire_core, "grd-vnc-pipewire-stream", NULL); min_rect = SPA_RECTANGLE (1, 1); max_rect = SPA_RECTANGLE (INT32_MAX, INT32_MAX); min_framerate = SPA_FRACTION (1, 1); max_framerate = SPA_FRACTION (30, 1); pod_builder = SPA_POD_BUILDER_INIT (params_buffer, sizeof (params_buffer)); params[0] = spa_pod_builder_add_object ( &pod_builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, SPA_FORMAT_mediaType, SPA_POD_Id (SPA_MEDIA_TYPE_video), SPA_FORMAT_mediaSubtype, SPA_POD_Id (SPA_MEDIA_SUBTYPE_raw), SPA_FORMAT_VIDEO_format, SPA_POD_Id (SPA_VIDEO_FORMAT_BGRx), SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle (&min_rect, &min_rect, &max_rect), SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction (&SPA_FRACTION(0, 1)), SPA_FORMAT_VIDEO_maxFramerate, SPA_POD_CHOICE_RANGE_Fraction (&min_framerate, &min_framerate, &max_framerate), 0); stream->pipewire_stream = pipewire_stream; pw_stream_add_listener (pipewire_stream, &stream->pipewire_stream_listener, &stream_events, stream); ret = pw_stream_connect (stream->pipewire_stream, PW_DIRECTION_INPUT, stream->src_node_id, (PW_STREAM_FLAG_RT_PROCESS | PW_STREAM_FLAG_AUTOCONNECT), params, 1); if (ret < 0) { g_set_error_literal (error, G_IO_ERROR, g_io_error_from_errno (-ret), strerror (-ret)); return FALSE; } return TRUE; } static void on_core_error (void *user_data, uint32_t id, int seq, int res, const char *message) { GrdVncPipeWireStream *stream = GRD_VNC_PIPEWIRE_STREAM (user_data); g_warning ("Pipewire core error: id:%u %s", id, message); if (id == PW_ID_CORE && res == -EPIPE) g_signal_emit (stream, signals[CLOSED], 0); } static const struct pw_core_events core_events = { PW_VERSION_CORE_EVENTS, .error = on_core_error, }; GrdVncPipeWireStream * grd_vnc_pipewire_stream_new (GrdSessionVnc *session_vnc, uint32_t src_node_id, GError **error) { g_autoptr (GrdVncPipeWireStream) stream = NULL; GrdPipeWireSource *pipewire_source; static gboolean is_pipewire_initialized = FALSE; if (!is_pipewire_initialized) { pw_init (NULL, NULL); is_pipewire_initialized = TRUE; } stream = g_object_new (GRD_TYPE_VNC_PIPEWIRE_STREAM, NULL); stream->session = session_vnc; stream->src_node_id = src_node_id; pipewire_source = create_pipewire_source (); if (!pipewire_source) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to create PipeWire source"); return NULL; } stream->pipewire_source = (GSource *) pipewire_source; stream->pipewire_context = pw_context_new (pipewire_source->pipewire_loop, NULL, 0); if (!stream->pipewire_context) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to create pipewire context"); return NULL; } stream->pipewire_core = pw_context_connect (stream->pipewire_context, NULL, 0); if (!stream->pipewire_core) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to connect pipewire context"); return NULL; } pw_core_add_listener (stream->pipewire_core, &stream->pipewire_core_listener, &core_events, stream); if (!connect_to_stream (stream, error)) return NULL; return g_steal_pointer (&stream); } static void grd_vnc_pipewire_stream_finalize (GObject *object) { GrdVncPipeWireStream *stream = GRD_VNC_PIPEWIRE_STREAM (object); /* * We can't clear stream->pipewire_stream before destroying it, as the data * thread in PipeWire might access the variable during destruction. */ if (stream->pipewire_stream) pw_stream_destroy (stream->pipewire_stream); g_clear_pointer (&stream->pipewire_core, pw_core_disconnect); g_clear_pointer (&stream->pipewire_context, pw_context_destroy); g_clear_pointer (&stream->pipewire_source, g_source_destroy); G_OBJECT_CLASS (grd_vnc_pipewire_stream_parent_class)->finalize (object); } static void grd_vnc_pipewire_stream_init (GrdVncPipeWireStream *stream) { g_mutex_init (&stream->frame_mutex); } static void grd_vnc_pipewire_stream_class_init (GrdVncPipeWireStreamClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = grd_vnc_pipewire_stream_finalize; signals[CLOSED] = g_signal_new ("closed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0); } 07070100000021000081A4000003E800000064000000015E7474AE00000583000000000000000000000000000000000000003900000000gnome-remote-desktop-0.1.8/src/grd-vnc-pipewire-stream.h/* * Copyright (C) 2018 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * */ #ifndef GRD_VNC_PIPEWIRE_STREAM_H #define GRD_VNC_PIPEWIRE_STREAM_H #include <glib-object.h> #include <stdint.h> #include "grd-session-vnc.h" #define GRD_TYPE_VNC_PIPEWIRE_STREAM grd_vnc_pipewire_stream_get_type () G_DECLARE_FINAL_TYPE (GrdVncPipeWireStream, grd_vnc_pipewire_stream, GRD, VNC_PIPEWIRE_STREAM, GObject) GrdVncPipeWireStream * grd_vnc_pipewire_stream_new (GrdSessionVnc *session_vnc, uint32_t src_node_id, GError **error); #endif /* GRD_VNC_PIPEWIRE_STREAM_H */ 07070100000022000081A4000003E800000064000000015E7474AE00001AAC000000000000000000000000000000000000003000000000gnome-remote-desktop-0.1.8/src/grd-vnc-server.c/* * Copyright (C) 2015 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by: * Jonas Ådahl <jadahl@gmail.com> */ #include "config.h" #include "grd-vnc-server.h" #include <gio/gio.h> #include <rfb/rfb.h> #include "grd-context.h" #include "grd-session-vnc.h" enum { PROP_0, PROP_CONTEXT, }; struct _GrdVncServer { GSocketService parent; GList *sessions; GList *stopped_sessions; guint idle_task; GrdContext *context; }; G_DEFINE_TYPE (GrdVncServer, grd_vnc_server, G_TYPE_SOCKET_SERVICE); GrdContext * grd_vnc_server_get_context (GrdVncServer *vnc_server) { return vnc_server->context; } GrdVncServer * grd_vnc_server_new (GrdContext *context) { GrdVncServer *vnc_server; vnc_server = g_object_new (GRD_TYPE_VNC_SERVER, "context", context, NULL); return vnc_server; } static void grd_vnc_server_cleanup_stopped_sessions (GrdVncServer *vnc_server) { g_list_free_full (vnc_server->stopped_sessions, g_object_unref); vnc_server->stopped_sessions = NULL; } static gboolean cleanup_stopped_sessions_idle (GrdVncServer *vnc_server) { grd_vnc_server_cleanup_stopped_sessions (vnc_server); vnc_server->idle_task = 0; return G_SOURCE_REMOVE; } static void on_session_stopped (GrdSession *session, GrdVncServer *vnc_server) { g_debug ("VNC session stopped"); vnc_server->stopped_sessions = g_list_append (vnc_server->stopped_sessions, session); vnc_server->sessions = g_list_remove (vnc_server->sessions, session); if (!vnc_server->idle_task) { vnc_server->idle_task = g_idle_add ((GSourceFunc) cleanup_stopped_sessions_idle, vnc_server); } } static gboolean on_incoming (GSocketService *service, GSocketConnection *connection) { GrdVncServer *vnc_server = GRD_VNC_SERVER (service); GrdSessionVnc *session_vnc; g_debug ("New incoming VNC connection"); if (vnc_server->sessions) { /* TODO: Add the rfbScreen instance to GrdVncServer to support multiple * sessions. */ g_debug ("Refusing new VNC connection: already an active session"); return TRUE; } session_vnc = grd_session_vnc_new (vnc_server, connection); vnc_server->sessions = g_list_append (vnc_server->sessions, session_vnc); grd_context_add_session (vnc_server->context, GRD_SESSION (session_vnc)); g_signal_connect (session_vnc, "stopped", G_CALLBACK (on_session_stopped), vnc_server); return TRUE; } gboolean grd_vnc_server_start (GrdVncServer *vnc_server, GError **error) { GrdSettings *settings = grd_context_get_settings (vnc_server->context); if (!g_socket_listener_add_inet_port (G_SOCKET_LISTENER (vnc_server), grd_settings_get_vnc_port (settings), NULL, error)) return FALSE; g_signal_connect (vnc_server, "incoming", G_CALLBACK (on_incoming), NULL); return TRUE; } static void stop_and_unref_session (GrdSession *session) { grd_session_stop (session); g_object_unref (session); } static void grd_vnc_server_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GrdVncServer *vnc_server = GRD_VNC_SERVER (object); switch (prop_id) { case PROP_CONTEXT: vnc_server->context = g_value_get_object (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void grd_vnc_server_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GrdVncServer *vnc_server = GRD_VNC_SERVER (object); switch (prop_id) { case PROP_CONTEXT: g_value_set_object (value, vnc_server->context); default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void grd_vnc_server_dispose (GObject *object) { GrdVncServer *vnc_server = GRD_VNC_SERVER (object); if (vnc_server->idle_task) { g_source_remove (vnc_server->idle_task); vnc_server->idle_task = 0; } if (vnc_server->stopped_sessions) { grd_vnc_server_cleanup_stopped_sessions (vnc_server); } if (vnc_server->sessions) { g_list_free_full (vnc_server->sessions, (GDestroyNotify) stop_and_unref_session); vnc_server->sessions = NULL; } G_OBJECT_CLASS (grd_vnc_server_parent_class)->dispose (object); } static void grd_vnc_server_constructed (GObject *object) { GrdVncServer *vnc_server = GRD_VNC_SERVER (object); if (grd_context_get_debug_flags (vnc_server->context) & GRD_DEBUG_VNC) rfbLogEnable (1); else rfbLogEnable (0); G_OBJECT_CLASS (grd_vnc_server_parent_class)->constructed (object); } static void grd_vnc_server_init (GrdVncServer *vnc_server) { } static void grd_vnc_server_class_init (GrdVncServerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->set_property = grd_vnc_server_set_property; object_class->get_property = grd_vnc_server_get_property; object_class->dispose = grd_vnc_server_dispose; object_class->constructed = grd_vnc_server_constructed; g_object_class_install_property (object_class, PROP_CONTEXT, g_param_spec_object ("context", "GrdContext", "The GrdContext instance", GRD_TYPE_CONTEXT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); } 07070100000023000081A4000003E800000064000000015E7474AE00000566000000000000000000000000000000000000003000000000gnome-remote-desktop-0.1.8/src/grd-vnc-server.h/* * Copyright (C) 2015 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * Written by: * Jonas Ådahl <jadahl@gmail.com> */ #ifndef GRD_VNC_SERVER_H #define GRD_VNC_SERVER_H #include <gio/gio.h> #include <glib-object.h> #include "grd-types.h" #define GRD_TYPE_VNC_SERVER (grd_vnc_server_get_type ()) G_DECLARE_FINAL_TYPE (GrdVncServer, grd_vnc_server, GRD, VNC_SERVER, GSocketService); GrdContext *grd_vnc_server_get_context (GrdVncServer *vnc_server); gboolean grd_vnc_server_start (GrdVncServer *vnc_server, GError **error); GrdVncServer *grd_vnc_server_new (GrdContext *context); #endif /* GRD_VNC_SERVER_H */ 07070100000024000081A4000003E800000064000000015E7474AE00000CD6000000000000000000000000000000000000002B00000000gnome-remote-desktop-0.1.8/src/meson.builddaemon_sources = files([ 'grd-context.c', 'grd-context.h', 'grd-daemon.c', 'grd-daemon.h', 'grd-private.h', 'grd-prompt.c', 'grd-prompt.h', 'grd-session.c', 'grd-session.h', 'grd-session-vnc.c', 'grd-session-vnc.h', 'grd-settings.c', 'grd-settings.h', 'grd-stream.c', 'grd-stream.h', 'grd-types.h', 'grd-vnc-cursor.c', 'grd-vnc-cursor.h', 'grd-vnc-pipewire-stream.c', 'grd-vnc-pipewire-stream.h', 'grd-vnc-server.c', 'grd-vnc-server.h', ]) gen_daemon_sources = [] gen_daemon_sources += gnome.gdbus_codegen('grd-dbus-screen-cast', 'org.gnome.Mutter.ScreenCast.xml', interface_prefix: 'org.gnome.Mutter.', namespace: 'GrdDBus') gen_daemon_sources += gnome.gdbus_codegen('grd-dbus-remote-desktop', 'org.gnome.Mutter.RemoteDesktop.xml', interface_prefix: 'org.gnome.Mutter.', namespace: 'GrdDBus') daemon_sources += gen_daemon_sources control_sources = ([ 'grd-control.c' ]) prefix = get_option('prefix') libexecdir = join_paths(prefix, get_option('libexecdir')) executable('gnome-remote-desktop-daemon', daemon_sources, dependencies: [glib_dep, gio_dep, gio_unix_dep, pipewire_dep, libvncserver_dep, libsecret_dep, libnotify_dep], include_directories: [configinc], install: true, install_dir: libexecdir) executable('gnome-remote-desktop-control', control_sources, dependencies: [glib_dep, gio_dep], include_directories: [configinc], install : false) service_config = configuration_data() service_config.set('libexecdir', libexecdir) configure_file(input: 'gnome-remote-desktop.service.in', output: 'gnome-remote-desktop.service', configuration: service_config, install_dir: servicedir) datadir = join_paths(prefix, get_option('datadir')) schemadir = join_paths(datadir, 'glib-2.0', 'schemas') custom_target('gsettings-enums', input: 'grd-enums.h', output: 'org.gnome.desktop.remote-desktop.enums.xml', install: true, install_dir: join_paths(datadir, 'glib-2.0', 'schemas'), capture: true, command: ['glib-mkenums', '--comments', '<!-- @comment@ -->', '--fhead', '<schemalist>', '--vhead', ' <@type@ id="org.gnome.desktop.remote-desktop.@EnumName@">', '--vprod', ' <value nick="@valuenick@" value="@valuenum@"/>', '--vtail', ' </@type@>', '--ftail', '</schemalist>', '@INPUT@']) schema = 'org.gnome.desktop.remote-desktop.gschema.xml' generated_schema = configure_file(output: schema, input: schema + '.in', copy: true) install_data(generated_schema, install_dir: schemadir) gnome.compile_schemas() 07070100000025000081A4000003E800000064000000015E7474AE00000945000000000000000000000000000000000000004200000000gnome-remote-desktop-0.1.8/src/org.gnome.Mutter.RemoteDesktop.xml<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN' 'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'> <node> <!-- org.gnome.Mutter.RemoteDesktop: @short_description: Remote desktop interface --> <interface name="org.gnome.Mutter.RemoteDesktop"> <!-- CreateSession: @session: Path to the new session object --> <method name="CreateSession"> <arg name="session_path" type="o" direction="out" /> </method> </interface> <!-- org.gnome.Mutter.RemoteDesktop.Session: @short_description: Remote desktop session --> <interface name="org.gnome.Mutter.RemoteDesktop.Session"> <!-- SessionId: An identification string used for identifying a remote desktop session. It can be used to associate screen cast sessions with a remote desktop session. --> <property name="SessionId" type="s" access="read" /> <!-- Start: Start the remote desktop session --> <method name="Start" /> <!-- Stop: Stop the remote desktop session --> <method name="Stop" /> <!-- Closed: The session has closed. A session doesn't have to have been started before it may be closed. After it being closed, it can no longer be used. --> <signal name="Closed" /> <!-- NotifyKeyboardKeysym: A key identified by a keysym was pressed or released --> <method name="NotifyKeyboardKeysym"> <arg name="keysym" type="u" direction="in" /> <arg name="state" type="b" direction="in" /> </method> <!-- NotifyPointerButton: A pointer button was pressed or released --> <method name="NotifyPointerButton"> <arg name="button" type="i" direction="in" /> <arg name="state" type="b" direction="in" /> </method> <!-- NotifyPointerAxisDiscrete: A discrete pointer axis event notification --> <method name="NotifyPointerAxisDiscrete"> <arg name="axis" type="u" direction="in" /> <arg name="steps" type="i" direction="in" /> </method> <!-- NotifyPointerMotionAbsolute: A absolute pointer motion event notification --> <method name="NotifyPointerMotionAbsolute"> <arg name="stream" type="s" direction="in" /> <arg name="x" type="d" direction="in" /> <arg name="y" type="d" direction="in" /> </method> </interface> </node> 07070100000026000081A4000003E800000064000000015E7474AE00000922000000000000000000000000000000000000003F00000000gnome-remote-desktop-0.1.8/src/org.gnome.Mutter.ScreenCast.xml<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN' 'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'> <node> <!-- org.gnome.Mutter.ScreenCast: @short_description: Screen cast interface Available @properties (see RecordMonitor and RecordWindow) --> <interface name="org.gnome.Mutter.ScreenCast"> <!-- CreateSession: @properties: Properties @session: Path to the new session object * "remote-desktop-session-id" (s): The ID of a remote desktop session. Remote desktop driven screen casts are started and stopped by the remote desktop session. --> <method name="CreateSession"> <arg name="properties" type="a{sv}" direction="in" /> <arg name="session_path" type="o" direction="out" /> </method> </interface> <interface name="org.gnome.Mutter.ScreenCast.Session"> <!-- Start: Start the screen cast session --> <method name="Start" /> <!-- Stop: Stop the screen cast session --> <method name="Stop" /> <!-- Closed: The session has closed. --> <signal name="Closed" /> <!-- RecordMonitor: @connector: Connector of the monitor to record @properties: Properties @session: Path to the new session object Record a single monitor. Available @properties include: (none) --> <method name="RecordMonitor"> <arg name="connector" type="s" direction="in" /> <arg name="properties" type="a{sv}" direction="in" /> <arg name="stream_path" type="o" direction="out" /> </method> <!-- RecordWindow: @properties: Properties @session: Path to the new session object Record a single monitor. Available @properties include: (none) --> <method name="RecordWindow"> <arg name="properties" type="a{sv}" direction="in" /> <arg name="stream_path" type="o" direction="out" /> </method> </interface> <!-- org.gnome.Mutter.ScreenCast.Session: @short_description: Screen cast session --> <interface name="org.gnome.Mutter.ScreenCast.Stream"> <!-- PipeWireStreamAdded: --> <signal name="PipeWireStreamAdded"> <annotation name="org.gtk.GDBus.C.Name" value="pipewire-stream-added"/> <arg name="node_id" type="u" direction="out" /> </signal> </interface> </node> 07070100000027000081A4000003E800000064000000015E7474AE00000498000000000000000000000000000000000000004F00000000gnome-remote-desktop-0.1.8/src/org.gnome.desktop.remote-desktop.gschema.xml.in<schemalist> <schema id='org.gnome.desktop.remote-desktop' path='/org/gnome/desktop/remote-desktop/'> </schema> <schema id='org.gnome.desktop.remote-desktop.vnc' path='/org/gnome/desktop/remote-desktop/vnc/'> <key name='view-only' type='b'> <default>true</default> <summary>Only allow remote connections to view the screen content</summary> <description> When view-only is true, remote VNC connections cannot manipulate input devices (e.g. mouse and keyboard). </description> </key> <key name='auth-method' enum='org.gnome.desktop.remote-desktop.GrdVncAuthMethod'> <default>'prompt'</default> <summary>Method used to authenticate VNC connections</summary> <description> The VNC authentication method describes how a remote connection is authenticated. It can currently be done in two different ways: * prompt - by prompting the user for each new connection, requiring a person with physical access to the workstation to explicitly approve the new connection. * password - by requiring the remote client to provide a known password </description> </key> </schema> </schemalist> 07070100000028000041ED000003E800000064000000025E7474AE00000000000000000000000000000000000000000000002100000000gnome-remote-desktop-0.1.8/tests07070100000029000081A4000003E800000064000000015E7474AE000001DE000000000000000000000000000000000000002D00000000gnome-remote-desktop-0.1.8/tests/meson.buildtest_client_vnc = executable( 'test-client-vnc', files(['test-client-vnc.c']), dependencies: [glib_dep, libvncclient_dep], include_directories: [configinc], install: false) test_runner = find_program('vnc-test-runner.sh') test_env = environment() test_env.set('TEST_SRCDIR', top_srcdir) test_env.set('TEST_BUILDDIR', builddir) test_env.set('NO_AT_BRIDGE', '1') test('gnome-remote-desktop/vnc', test_runner, env: test_env, is_parallel: false, timeout: 10, ) 0707010000002A000081ED000003E800000064000000015E7474AE00000A22000000000000000000000000000000000000003200000000gnome-remote-desktop-0.1.8/tests/run-vnc-tests.py#!/usr/bin/python3 import dbus import os import time import os.path import subprocess import sys from gi.repository import GLib from dbus.mainloop.glib import DBusGMainLoop mutter = None DBusGMainLoop(set_as_default=True) loop = GLib.MainLoop() bus = dbus.SessionBus() vnc_client_failed = None vnc_server_failed = None os.environ['GNOME_REMOTE_DESKTOP_TEST_VNC_PASSWORD'] = 'secret' os.environ['MUTTER_DEBUG_DUMMY_MODE_SPECS'] = '1024x768' def run_vnc_test_client(): print("Running VNC test client") global vnc_client_failed builddir=os.getenv("TEST_BUILDDIR") vnc_test_client_path = os.path.join(builddir, 'tests', 'test-client-vnc') vnc_test_client = subprocess.Popen([vnc_test_client_path, 'localhost:5912'], stderr=subprocess.STDOUT) vnc_test_client.wait() if vnc_test_client.wait() != 0: print("VNC test client exited incorrectly") vnc_client_failed = True else: vnc_client_failed = False def start_vnc_server(): print("Starting VNC server") global vnc_server builddir=os.getenv("TEST_BUILDDIR") vnc_server_path = os.path.join(builddir, 'src', 'gnome-remote-desktop-daemon') vnc_server = subprocess.Popen([vnc_server_path, '--vnc-port', '5912'], stderr=subprocess.STDOUT) time.sleep(1) def stop_vnc_server(): print("Stopping VNC server") global vnc_server global vnc_server_failed vnc_server.terminate() vnc_server.wait() if vnc_server.returncode != -15 and vnc_server.returncode != 0: print("VNC server exited incorrectly: %d"%(vnc_server.returncode)) vnc_server_failed = True else: vnc_server_failed = False def remote_desktop_name_appeared_cb(name): if name == '': return print("Remote desktop capable display server appeared") start_vnc_server() run_vnc_test_client() stop_vnc_server() stop_mutter() def start_mutter(): global mutter print("Starting mutter") mutter = subprocess.Popen(['mutter', '--nested', '--wayland'], stderr=subprocess.STDOUT) def stop_mutter(): global mutter global loop if mutter == None: print("no mutter") return print("Stopping mutter") mutter.terminate() print("Waiting for mutter to terminate") if mutter.wait() != 0: print("Mutter exited incorrectly") sys.exit(1) print("Done") loop.quit() bus.watch_name_owner('org.gnome.Mutter.RemoteDesktop', remote_desktop_name_appeared_cb) start_mutter() loop.run() if vnc_server_failed != False or vnc_client_failed != False: sys.exit(1) else: sys.exit(0) 0707010000002B000081A4000003E800000064000000015E7474AE00000C73000000000000000000000000000000000000003300000000gnome-remote-desktop-0.1.8/tests/test-client-vnc.c/* * Copyright (C) 2019 Red Hat Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * */ #include "config.h" #include <glib.h> #include <rfb/rfbclient.h> #include <stdio.h> static gboolean saw_correct_size = FALSE; static rfbBool handle_malloc_framebuffer (rfbClient *rfb_client) { if (rfb_client->width == 1024 && rfb_client->height == 768) saw_correct_size = TRUE; g_clear_pointer (&rfb_client->frameBuffer, g_free); rfb_client->frameBuffer = g_malloc0 (rfb_client->width * rfb_client->height * rfb_client->format.bitsPerPixel / 4); return TRUE; } static void handle_got_framebuffer_update (rfbClient *rfb_client, int x, int y, int width, int height) { if (saw_correct_size) exit(EXIT_SUCCESS); } static char * handle_get_password (rfbClient *rfb_client) { const char *test_password; test_password = g_getenv ("GNOME_REMOTE_DESKTOP_TEST_VNC_PASSWORD"); g_assert (test_password); return g_strdup (test_password); } int main (int argc, char **argv) { rfbClient *rfb_client; const int bits_per_sample = 8; const int samples_per_pixel = 3; const int bytes_per_pixel = 4; rfb_client = rfbGetClient (bits_per_sample, samples_per_pixel, bytes_per_pixel); rfb_client->MallocFrameBuffer = handle_malloc_framebuffer; rfb_client->canHandleNewFBSize = TRUE; rfb_client->GotFrameBufferUpdate = handle_got_framebuffer_update; rfb_client->GetPassword = handle_get_password; rfb_client->listenPort = LISTEN_PORT_OFFSET; rfb_client->listen6Port = LISTEN_PORT_OFFSET; if (!rfbInitClient (rfb_client, &argc, argv)) { g_warning ("Failed to initialize VNC client"); return EXIT_FAILURE; } while (TRUE) { int ret; const int timeout_us = 500; ret = WaitForMessage (rfb_client, timeout_us); if (ret < 0) { g_warning ("WaitForMessage failed"); rfbClientCleanup (rfb_client); return EXIT_FAILURE; } else if (ret > 0) { if (!HandleRFBServerMessage (rfb_client)) { g_warning ("HandleRFBServerMessage failed"); rfbClientCleanup (rfb_client); return EXIT_FAILURE; } } } } 0707010000002C000081ED000003E800000064000000015E7474AE00000066000000000000000000000000000000000000003400000000gnome-remote-desktop-0.1.8/tests/vnc-test-runner.sh#!/usr/bin/bash dbus-run-session -- xvfb-run -s '+iglx -noreset' $TEST_SRCDIR/tests/run-vnc-tests.py 07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!318 blocks
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor