2023-09-26 00:35:21 +02:00
|
|
|
/* PIKA - Photo and Image Kooker Application
|
|
|
|
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
|
|
|
|
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
|
|
|
|
*
|
|
|
|
* Original copyright, applying to most contents (license remains unchanged):
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* Screenshot plug-in
|
|
|
|
* Copyright 1998-2007 Sven Neumann <sven@gimp.org>
|
|
|
|
* Copyright 2003 Henrik Brix Andersen <brix@gimp.org>
|
|
|
|
* Copyright 2012 Simone Karin Lehmann - OS X patches
|
|
|
|
*
|
|
|
|
* 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 3 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, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef PLATFORM_OSX
|
|
|
|
|
|
|
|
#include <stdlib.h> /* for system() on OSX */
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gstdio.h> /* g_unlink() */
|
|
|
|
|
|
|
|
#include <libpika/pika.h>
|
|
|
|
#include <libpika/pikaui.h>
|
|
|
|
|
|
|
|
#include "screenshot.h"
|
|
|
|
#include "screenshot-osx.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mac OS X uses a rootless X server. This won't let us use
|
|
|
|
* gdk_pixbuf_get_from_drawable() and similar function on the root
|
|
|
|
* window to get the entire screen contents. With a native OS X build
|
|
|
|
* we have to do this without X as well.
|
|
|
|
*
|
|
|
|
* Since Mac OS X 10.2 a system utility for screencapturing is
|
|
|
|
* included. We can safely use this, since it's available on every OS
|
|
|
|
* X version PIKA is running on.
|
|
|
|
*
|
|
|
|
* The main drawbacks are that it's not possible to shoot windows or
|
|
|
|
* regions in scripts in noninteractive mode, and that windows always
|
|
|
|
* include decorations, since decorations are different between X11
|
|
|
|
* windows and native OS X app windows. But we can use this switch
|
|
|
|
* to capture the shadow of a window, which is indeed very Mac-ish.
|
|
|
|
*
|
|
|
|
* This routines works well with X11 and as a native build.
|
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
screenshot_osx_available (void)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScreenshotCapabilities
|
|
|
|
screenshot_osx_get_capabilities (void)
|
|
|
|
{
|
|
|
|
return (SCREENSHOT_CAN_SHOOT_DECORATIONS |
|
|
|
|
SCREENSHOT_CAN_SHOOT_POINTER |
|
|
|
|
SCREENSHOT_CAN_SHOOT_REGION |
|
|
|
|
SCREENSHOT_CAN_SHOOT_WINDOW |
|
|
|
|
SCREENSHOT_CAN_PICK_WINDOW |
|
|
|
|
SCREENSHOT_CAN_DELAY_WINDOW_SHOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
PikaPDBStatusType
|
2023-10-30 23:55:30 +01:00
|
|
|
screenshot_osx_shoot (ShootType shoot_type,
|
|
|
|
guint select_delay,
|
|
|
|
guint screenshot_delay,
|
|
|
|
gboolean decorate,
|
|
|
|
gboolean show_cursor,
|
|
|
|
PikaImage **image,
|
|
|
|
GError **error)
|
2023-09-26 00:35:21 +02:00
|
|
|
{
|
|
|
|
const gchar *mode = " ";
|
|
|
|
const gchar *cursor = " ";
|
|
|
|
gchar *delay = NULL;
|
|
|
|
GFile *tmpfile;
|
|
|
|
gchar *quoted;
|
|
|
|
gchar *command = NULL;
|
|
|
|
|
2023-10-30 23:55:30 +01:00
|
|
|
switch (shoot_type)
|
2023-09-26 00:35:21 +02:00
|
|
|
{
|
|
|
|
case SHOOT_REGION:
|
2023-10-30 23:55:30 +01:00
|
|
|
if (select_delay > 0)
|
|
|
|
screenshot_wait_delay (select_delay);
|
2023-09-26 00:35:21 +02:00
|
|
|
|
|
|
|
mode = "-is";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHOOT_WINDOW:
|
2023-10-30 23:55:30 +01:00
|
|
|
if (select_delay > 0)
|
|
|
|
screenshot_wait_delay (select_delay);
|
2023-09-26 00:35:21 +02:00
|
|
|
|
2023-10-30 23:55:30 +01:00
|
|
|
if (decorate)
|
2023-09-26 00:35:21 +02:00
|
|
|
mode = "-iwo";
|
|
|
|
else
|
|
|
|
mode = "-iw";
|
2023-10-30 23:55:30 +01:00
|
|
|
if (show_cursor)
|
2023-09-26 00:35:21 +02:00
|
|
|
cursor = "-C";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHOOT_ROOT:
|
|
|
|
mode = " ";
|
2023-10-30 23:55:30 +01:00
|
|
|
if (show_cursor)
|
2023-09-26 00:35:21 +02:00
|
|
|
cursor = "-C";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_return_val_if_reached (PIKA_PDB_CALLING_ERROR);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-10-30 23:55:30 +01:00
|
|
|
delay = g_strdup_printf ("-T %i", screenshot_delay);
|
2023-09-26 00:35:21 +02:00
|
|
|
|
|
|
|
tmpfile = pika_temp_file ("png");
|
|
|
|
quoted = g_shell_quote (g_file_peek_path (tmpfile));
|
|
|
|
|
|
|
|
command = g_strjoin (" ",
|
|
|
|
"/usr/sbin/screencapture",
|
|
|
|
mode,
|
|
|
|
cursor,
|
|
|
|
delay,
|
|
|
|
quoted,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_free (quoted);
|
|
|
|
g_free (delay);
|
|
|
|
|
|
|
|
if (system ((const char *) command) == EXIT_SUCCESS)
|
|
|
|
{
|
|
|
|
/* don't attach a profile, screencapture attached one
|
|
|
|
*/
|
|
|
|
|
|
|
|
*image = pika_file_load (PIKA_RUN_NONINTERACTIVE,
|
|
|
|
tmpfile);
|
|
|
|
|
|
|
|
g_file_delete (tmpfile, NULL, NULL);
|
|
|
|
g_free (command);
|
|
|
|
|
|
|
|
return PIKA_PDB_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (command);
|
|
|
|
|
|
|
|
return PIKA_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* PLATFORM_OSX */
|