Blame SOURCES/0001-utils-Drop-gdm-screenshot.patch

ffa191
From 7b5ee288d992f85eaefbfbc4dac663a29fcae446 Mon Sep 17 00:00:00 2001
ffa191
From: Ray Strode <rstrode@redhat.com>
ffa191
Date: Wed, 5 May 2021 11:06:58 -0400
ffa191
Subject: [PATCH] 0001-utils-Drop-gdm-screenshot.patch
ffa191
ffa191
---
ffa191
 utils/gdm-screenshot.c | 296 -----------------------------------------
ffa191
 utils/meson.build      |  15 ---
ffa191
 2 files changed, 311 deletions(-)
ffa191
 delete mode 100644 utils/gdm-screenshot.c
ffa191
ffa191
diff --git a/utils/gdm-screenshot.c b/utils/gdm-screenshot.c
ffa191
deleted file mode 100644
ffa191
index 5d20929a3..000000000
ffa191
--- a/utils/gdm-screenshot.c
ffa191
+++ /dev/null
ffa191
@@ -1,296 +0,0 @@
ffa191
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
ffa191
- *
ffa191
- * Copyright (C) 2008 William Jon McCann <jmccann@redhat.com>
ffa191
- *
ffa191
- * This program is free software; you can redistribute it and/or modify
ffa191
- * it under the terms of the GNU General Public License as published by
ffa191
- * the Free Software Foundation; either version 2 of the License, or
ffa191
- * (at your option) any later version.
ffa191
- *
ffa191
- * This program is distributed in the hope that it will be useful,
ffa191
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
ffa191
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ffa191
- * GNU General Public License for more details.
ffa191
- *
ffa191
- * You should have received a copy of the GNU General Public License
ffa191
- * along with this program; if not, write to the Free Software
ffa191
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
ffa191
- *
ffa191
- */
ffa191
-
ffa191
-#include "config.h"
ffa191
-
ffa191
-#include <stdlib.h>
ffa191
-#include <stdio.h>
ffa191
-#include <unistd.h>
ffa191
-#include <string.h>
ffa191
-#include <locale.h>
ffa191
-
ffa191
-#include <glib/gi18n.h>
ffa191
-#include <gtk/gtk.h>
ffa191
-#include <canberra-gtk.h>
ffa191
-
ffa191
-#include <X11/Xatom.h>
ffa191
-#include <gdk/gdkx.h>
ffa191
-
ffa191
-#define SELECTION_NAME "_GDM_SCREENSHOT"
ffa191
-static GtkWidget *selection_window;
ffa191
-
ffa191
-static gboolean debug_in;
ffa191
-
ffa191
-/* Keep all config options for compatibility even if they are noops */
ffa191
-GOptionEntry options [] = {
ffa191
-        { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug_in, N_("Debugging output"), NULL },
ffa191
-        { NULL }
ffa191
-};
ffa191
-
ffa191
-/* To make sure there is only one screenshot taken at a time,
ffa191
- * (Imagine key repeat for the print screen key) we hold a selection
ffa191
- * until we are done taking the screenshot
ffa191
- */
ffa191
-/*  * Copyright (C) 2001-2006  Jonathan Blandford <jrb@alum.mit.edu> */
ffa191
-static gboolean
ffa191
-screenshot_grab_lock (void)
ffa191
-{
ffa191
-        Atom       selection_atom;
ffa191
-        GdkCursor *cursor;
ffa191
-        gboolean   result = FALSE;
ffa191
-
ffa191
-        selection_atom = gdk_x11_get_xatom_by_name (SELECTION_NAME);
ffa191
-        XGrabServer (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
ffa191
-        if (XGetSelectionOwner (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), selection_atom) != None) {
ffa191
-                goto out;
ffa191
-        }
ffa191
-
ffa191
-        selection_window = gtk_invisible_new ();
ffa191
-        gtk_widget_show (selection_window);
ffa191
-
ffa191
-        if (!gtk_selection_owner_set (selection_window,
ffa191
-                                      gdk_atom_intern (SELECTION_NAME, FALSE),
ffa191
-                                      GDK_CURRENT_TIME)) {
ffa191
-                gtk_widget_destroy (selection_window);
ffa191
-                selection_window = NULL;
ffa191
-                goto out;
ffa191
-        }
ffa191
-
ffa191
-        cursor = gdk_cursor_new_for_display (gdk_display_get_default (), GDK_WATCH);
ffa191
-        gdk_pointer_grab (gtk_widget_get_window (selection_window), FALSE, 0, NULL,
ffa191
-                          cursor, GDK_CURRENT_TIME);
ffa191
-        g_object_unref (cursor);
ffa191
-
ffa191
-        result = TRUE;
ffa191
-
ffa191
- out:
ffa191
-        XUngrabServer (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
ffa191
-        gdk_flush ();
ffa191
-
ffa191
-        return result;
ffa191
-}
ffa191
-
ffa191
-/*  * Copyright (C) 2001-2006  Jonathan Blandford <jrb@alum.mit.edu> */
ffa191
-static void
ffa191
-screenshot_release_lock (void)
ffa191
-{
ffa191
-        if (selection_window != NULL) {
ffa191
-                gtk_widget_destroy (selection_window);
ffa191
-                selection_window = NULL;
ffa191
-        }
ffa191
-        gdk_flush ();
ffa191
-}
ffa191
-
ffa191
-/*  * Copyright (C) 2001-2006  Jonathan Blandford <jrb@alum.mit.edu> */
ffa191
-static GdkPixbuf *
ffa191
-screenshot_get_pixbuf (Window w)
ffa191
-{
ffa191
-        GdkWindow *window;
ffa191
-        GdkWindow *root;
ffa191
-        GdkPixbuf *screenshot;
ffa191
-        int        x_real_orig;
ffa191
-        int        y_real_orig;
ffa191
-        int        x_orig;
ffa191
-        int        y_orig;
ffa191
-        int        real_width;
ffa191
-        int        real_height;
ffa191
-        int        width;
ffa191
-        int        height;
ffa191
-
ffa191
-        window = gdk_x11_window_foreign_new_for_display (gdk_display_get_default (), w);
ffa191
-        if (window == NULL) {
ffa191
-                return NULL;
ffa191
-        }
ffa191
-
ffa191
-        root = gdk_x11_window_foreign_new_for_display (gdk_display_get_default (), GDK_ROOT_WINDOW ());
ffa191
-        gdk_window_get_geometry (window, NULL, NULL, &real_width, &real_height);
ffa191
-        gdk_window_get_origin (window, &x_real_orig, &y_real_orig);
ffa191
-
ffa191
-        x_orig = x_real_orig;
ffa191
-        y_orig = y_real_orig;
ffa191
-        width = real_width;
ffa191
-        height = real_height;
ffa191
-
ffa191
-        if (x_orig < 0) {
ffa191
-                width = width + x_orig;
ffa191
-                x_orig = 0;
ffa191
-        }
ffa191
-        if (y_orig < 0) {
ffa191
-                height = height + y_orig;
ffa191
-                y_orig = 0;
ffa191
-        }
ffa191
-
ffa191
-        if (x_orig + width > gdk_screen_width ()) {
ffa191
-                width = gdk_screen_width () - x_orig;
ffa191
-        }
ffa191
-        if (y_orig + height > gdk_screen_height ()) {
ffa191
-                height = gdk_screen_height () - y_orig;
ffa191
-        }
ffa191
-
ffa191
-        screenshot = gdk_pixbuf_get_from_window (root,
ffa191
-                                                 x_orig,
ffa191
-                                                 y_orig,
ffa191
-                                                 width,
ffa191
-                                                 height);
ffa191
-
ffa191
-        return screenshot;
ffa191
-}
ffa191
-
ffa191
-static char *
ffa191
-screenshot_save (GdkPixbuf *pixbuf)
ffa191
-{
ffa191
-        char       *filename;
ffa191
-        gboolean    res;
ffa191
-        GError     *error;
ffa191
-
ffa191
-        filename = g_build_filename (GDM_SCREENSHOT_DIR,
ffa191
-                                     "GDM-Screenshot.png",
ffa191
-                                     NULL);
ffa191
-
ffa191
-        error = NULL;
ffa191
-        res = gdk_pixbuf_save (pixbuf,
ffa191
-                               filename,
ffa191
-                               "png",
ffa191
-                               &error,
ffa191
-                               "tEXt::CREATOR", "gdm-screenshot",
ffa191
-                               NULL);
ffa191
-        if (! res) {
ffa191
-                g_warning ("Unable to save screenshot: %s", error->message);
ffa191
-                g_error_free (error);
ffa191
-                g_free (filename);
ffa191
-                filename = NULL;
ffa191
-        }
ffa191
-
ffa191
-        return filename;
ffa191
-}
ffa191
-
ffa191
-static void
ffa191
-sound_effect_finished (ca_context *c,
ffa191
-                       uint32_t    id,
ffa191
-                       int         error_code,
ffa191
-                       void       *userdata)
ffa191
-{
ffa191
-}
ffa191
-
ffa191
-static void
ffa191
-play_sound_effect (Window xid)
ffa191
-{
ffa191
-        ca_context  *c;
ffa191
-        ca_proplist *p;
ffa191
-        int          res;
ffa191
-
ffa191
-        c = ca_gtk_context_get ();
ffa191
-
ffa191
-        p = NULL;
ffa191
-        res = ca_proplist_create (&p);
ffa191
-        if (res < 0) {
ffa191
-                goto done;
ffa191
-        }
ffa191
-
ffa191
-        res = ca_proplist_sets (p, CA_PROP_EVENT_ID, "screen-capture");
ffa191
-        if (res < 0) {
ffa191
-                goto done;
ffa191
-        }
ffa191
-
ffa191
-        res = ca_proplist_sets (p, CA_PROP_EVENT_DESCRIPTION, _("Screenshot taken"));
ffa191
-        if (res < 0) {
ffa191
-                goto done;
ffa191
-        }
ffa191
-
ffa191
-        res = ca_proplist_setf (p,
ffa191
-                                CA_PROP_WINDOW_X11_XID,
ffa191
-                                "%lu",
ffa191
-                                (unsigned long) xid);
ffa191
-        if (res < 0) {
ffa191
-                goto done;
ffa191
-        }
ffa191
-
ffa191
-        ca_context_play_full (c, 0, p, sound_effect_finished, NULL);
ffa191
-
ffa191
- done:
ffa191
-        if (p != NULL) {
ffa191
-                ca_proplist_destroy (p);
ffa191
-        }
ffa191
-
ffa191
-}
ffa191
-
ffa191
-static void
ffa191
-prepare_screenshot (void)
ffa191
-{
ffa191
-        Window     win;
ffa191
-        GdkPixbuf *screenshot;
ffa191
-        char      *filename;
ffa191
-
ffa191
-        if (!screenshot_grab_lock ()) {
ffa191
-                exit (EXIT_SUCCESS);
ffa191
-        }
ffa191
-
ffa191
-        win = GDK_ROOT_WINDOW ();
ffa191
-
ffa191
-        screenshot = screenshot_get_pixbuf (win);
ffa191
-
ffa191
-        screenshot_release_lock ();
ffa191
-
ffa191
-        if (screenshot == NULL) {
ffa191
-                /* FIXME: dialog? */
ffa191
-                exit (EXIT_FAILURE);
ffa191
-        }
ffa191
-
ffa191
-        play_sound_effect (win);
ffa191
-
ffa191
-        filename = screenshot_save (screenshot);
ffa191
-        if (filename != NULL) {
ffa191
-                g_print ("Wrote %s\n", filename);
ffa191
-                /* FIXME: show a dialog or something */
ffa191
-                g_free (filename);
ffa191
-        }
ffa191
-}
ffa191
-
ffa191
-int
ffa191
-main (int argc, char *argv[])
ffa191
-{
ffa191
-        GOptionContext *ctx;
ffa191
-        gboolean        res;
ffa191
-        GError         *error;
ffa191
-
ffa191
-        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
ffa191
-        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
ffa191
-        textdomain (GETTEXT_PACKAGE);
ffa191
-        setlocale (LC_ALL, "");
ffa191
-
ffa191
-        /* Option parsing */
ffa191
-        ctx = g_option_context_new (N_("Take a picture of the screen"));
ffa191
-        g_option_context_set_translation_domain (ctx, GETTEXT_PACKAGE);
ffa191
-        g_option_context_add_main_entries (ctx, options, NULL);
ffa191
-        g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
ffa191
-        error = NULL;
ffa191
-        res = g_option_context_parse (ctx, &argc, &argv, &error);
ffa191
-        g_option_context_free (ctx);
ffa191
-
ffa191
-        if (! res) {
ffa191
-                g_warning ("%s", error->message);
ffa191
-                g_error_free (error);
ffa191
-                exit (EXIT_FAILURE);
ffa191
-        }
ffa191
-
ffa191
-        prepare_screenshot ();
ffa191
-
ffa191
-        return 1;
ffa191
-}
ffa191
diff --git a/utils/meson.build b/utils/meson.build
ffa191
index d59f167b0..1edd7bce4 100644
ffa191
--- a/utils/meson.build
ffa191
+++ b/utils/meson.build
ffa191
@@ -1,41 +1,26 @@
ffa191
 # gdm-flexiserver
ffa191
 gdm_flexiserver_deps = [
ffa191
   glib_dep,
ffa191
   libgdmcommon_dep,
ffa191
 ]
ffa191
 
ffa191
 gdm_flexiserver = executable('gdmflexiserver',
ffa191
   'gdmflexiserver.c',
ffa191
   dependencies: gdm_flexiserver_deps,
ffa191
   include_directories: config_h_dir,
ffa191
   install: true,
ffa191
 )
ffa191
 
ffa191
-# gdm-screenshot
ffa191
-gdm_screenshot_deps = [
ffa191
-  glib_dep,
ffa191
-  gtk_dep,
ffa191
-  x_deps,
ffa191
-  libcanberra_gtk_dep,
ffa191
-]
ffa191
-
ffa191
-gdm_screenshot = executable('gdm-screenshot',
ffa191
-  'gdm-screenshot.c',
ffa191
-  dependencies: gdm_screenshot_deps,
ffa191
-  include_directories: config_h_dir,
ffa191
-  install: true,
ffa191
-)
ffa191
-
ffa191
 # gdm-runtime-config
ffa191
 gdm_runtime_config_deps = [
ffa191
   glib_dep,
ffa191
 ]
ffa191
 
ffa191
 gdm_runtime_config = executable('gdm-runtime-config',
ffa191
   'gdm-runtime-config.c',
ffa191
   dependencies: gdm_runtime_config_deps,
ffa191
   include_directories: config_h_dir,
ffa191
   install: true,
ffa191
   install_dir: get_option('libexecdir'),
ffa191
 )
ffa191
 
ffa191
-- 
ffa191
2.31.1
ffa191