Compare commits
1 Commits
frame-cloc
...
fix_toolti
Author | SHA1 | Date | |
---|---|---|---|
|
bd206f3b7a |
130
.gitlab-ci.yml
130
.gitlab-ci.yml
@@ -26,31 +26,25 @@ variables:
|
||||
BACKEND_FLAGS: "-Dx11-backend=true -Dwayland-backend=true -Dbroadway-backend=true"
|
||||
FEATURE_FLAGS: "-Dvulkan=enabled -Dcloudproviders=enabled -Ddemos=false -Dbuild-examples=false -Dbuild-tests=false -Dbuild-testsuite=true"
|
||||
MESON_TEST_TIMEOUT_MULTIPLIER: 3
|
||||
FEDORA_IMAGE: "registry.gitlab.gnome.org/gnome/gtk/fedora:v41"
|
||||
FEDORA_IMAGE: "registry.gitlab.gnome.org/gnome/gtk/fedora:v40"
|
||||
FLATPAK_IMAGE: "quay.io/gnome_infrastructure/gnome-runtime-images:gnome-master"
|
||||
|
||||
workflow:
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
- if: $CI_COMMIT_BRANCH
|
||||
|
||||
default:
|
||||
retry:
|
||||
max: 2
|
||||
when:
|
||||
- 'runner_system_failure'
|
||||
- 'stuck_or_timeout_failure'
|
||||
- 'scheduler_failure'
|
||||
- 'api_failure'
|
||||
interruptible: true
|
||||
.only-default:
|
||||
only:
|
||||
- branches
|
||||
except:
|
||||
- tags
|
||||
|
||||
style-check-diff:
|
||||
extends: .only-default
|
||||
image: $FEDORA_IMAGE
|
||||
stage: check
|
||||
when: manual
|
||||
allow_failure: true
|
||||
script:
|
||||
- .gitlab-ci/run-style-check-diff.sh
|
||||
|
||||
.build-fedora-default:
|
||||
extends: .only-default
|
||||
image: $FEDORA_IMAGE
|
||||
artifacts:
|
||||
when: always
|
||||
@@ -166,6 +160,7 @@ fedora-mingw64:
|
||||
- ninja -C _build
|
||||
|
||||
.mingw-defaults:
|
||||
extends: .only-default
|
||||
stage: build
|
||||
tags:
|
||||
- win32-ps
|
||||
@@ -197,8 +192,9 @@ msys2-mingw64:
|
||||
macos:
|
||||
# Sadly, this fails regularly, and its failure is never enlightening
|
||||
allow_failure: true
|
||||
rules:
|
||||
- if: $CI_PROJECT_NAMESPACE == "GNOME"
|
||||
extends: .only-default
|
||||
only:
|
||||
- branches@GNOME/gtk
|
||||
stage: build
|
||||
tags:
|
||||
- macos
|
||||
@@ -231,9 +227,10 @@ macos:
|
||||
- "${CI_PROJECT_DIR}/_build/meson-logs"
|
||||
|
||||
vs2017-x64:
|
||||
extends: .only-default
|
||||
# TODO: Uncomment this when ready to merge.
|
||||
# rules:
|
||||
# - if: $CI_PROJECT_NAMESPACE == "GNOME"
|
||||
#only:
|
||||
# - branches@GNOME/gtk
|
||||
stage: build
|
||||
tags:
|
||||
- win32-ps
|
||||
@@ -246,7 +243,7 @@ vs2017-x64:
|
||||
- "${CI_PROJECT_DIR}/_build/meson-logs"
|
||||
|
||||
.flatpak-defaults:
|
||||
image: "quay.io/gnome_infrastructure/gnome-runtime-images:gnome-master"
|
||||
image: $FLATPAK_IMAGE
|
||||
stage: flatpak
|
||||
allow_failure: true
|
||||
tags:
|
||||
@@ -256,67 +253,65 @@ vs2017-x64:
|
||||
- "${APPID}-dev.flatpak"
|
||||
- 'repo.tar'
|
||||
expire_in: 1 day
|
||||
rules:
|
||||
# Only build Flatpak bundles automatically on main
|
||||
- if: $CI_COMMIT_BRANCH == "main"
|
||||
- if: $CI_COMMIT_BRANCH != "main"
|
||||
when: "manual"
|
||||
script:
|
||||
- bash -x ./.gitlab-ci/flatpak-build.sh "${APPID}"
|
||||
|
||||
flatpak:demo:
|
||||
extends: '.flatpak-defaults'
|
||||
# Manual jobs, for branches and MRs
|
||||
.flatpak-manual:
|
||||
extends: .flatpak-defaults
|
||||
when: manual
|
||||
|
||||
# Only build Flatpak bundles automatically on main
|
||||
.flatpak-main:
|
||||
extends: .flatpak-defaults
|
||||
only:
|
||||
- main
|
||||
|
||||
flatpak-manual:demo:
|
||||
extends: .flatpak-manual
|
||||
needs: []
|
||||
variables:
|
||||
APPID: org.gtk.Demo4
|
||||
|
||||
flatpak:demo:aarch64:
|
||||
extends: '.flatpak-defaults'
|
||||
flatpak-main:demo:
|
||||
extends: .flatpak-main
|
||||
needs: []
|
||||
tags:
|
||||
- flatpak-aarch64
|
||||
variables:
|
||||
APPID: org.gtk.Demo4
|
||||
|
||||
flatpak:widget-factory:
|
||||
extends: '.flatpak-defaults'
|
||||
flatpak-manual:widget-factory:
|
||||
extends: .flatpak-manual
|
||||
needs: []
|
||||
variables:
|
||||
APPID: org.gtk.WidgetFactory4
|
||||
|
||||
flatpak:widget-factory:aarch64:
|
||||
extends: '.flatpak-defaults'
|
||||
flatpak-main:widget-factory:
|
||||
extends: .flatpak-main
|
||||
needs: []
|
||||
tags:
|
||||
- flatpak-aarch64
|
||||
variables:
|
||||
APPID: org.gtk.WidgetFactory4
|
||||
|
||||
flatpak:icon-browser:
|
||||
extends: '.flatpak-defaults'
|
||||
flatpak-manual:icon-browser:
|
||||
extends: .flatpak-manual
|
||||
needs: []
|
||||
variables:
|
||||
APPID: org.gtk.IconBrowser4
|
||||
|
||||
flatpak:icon-browser:aarch64:
|
||||
extends: '.flatpak-defaults'
|
||||
flatpak-main:icon-browser:
|
||||
extends: .flatpak-main
|
||||
needs: []
|
||||
tags:
|
||||
- flatpak-aarch64
|
||||
variables:
|
||||
APPID: org.gtk.IconBrowser4
|
||||
|
||||
flatpak:node-editor:
|
||||
extends: '.flatpak-defaults'
|
||||
flatpak-manual:node-editor:
|
||||
extends: .flatpak-manual
|
||||
needs: []
|
||||
variables:
|
||||
APPID: org.gtk.gtk4.NodeEditor
|
||||
|
||||
flatpak:node-editor:aarch64:
|
||||
extends: '.flatpak-defaults'
|
||||
flatpak-main:node-editor:
|
||||
extends: .flatpak-main
|
||||
needs: []
|
||||
tags:
|
||||
- flatpak-aarch64
|
||||
variables:
|
||||
APPID: org.gtk.gtk4.NodeEditor
|
||||
|
||||
@@ -325,35 +320,23 @@ flatpak:node-editor:aarch64:
|
||||
# https://gitlab.gnome.org/GNOME/Initiatives/-/wikis/DevOps-with-Flatpak
|
||||
nightly demo:
|
||||
extends: '.publish_nightly'
|
||||
needs: ['flatpak:demo']
|
||||
|
||||
nightly demo aarch64:
|
||||
extends: '.publish_nightly'
|
||||
needs: ['flatpak:demo:aarch64']
|
||||
dependencies: ['flatpak-main:demo']
|
||||
needs: ['flatpak-main:demo']
|
||||
|
||||
nightly factory:
|
||||
extends: '.publish_nightly'
|
||||
needs: ['flatpak:widget-factory']
|
||||
|
||||
nightly factory aarch64:
|
||||
extends: '.publish_nightly'
|
||||
needs: ['flatpak:widget-factory:aarch64']
|
||||
dependencies: ['flatpak-main:widget-factory']
|
||||
needs: ['flatpak-main:widget-factory']
|
||||
|
||||
nightly icon-browser:
|
||||
extends: '.publish_nightly'
|
||||
needs: ['flatpak:icon-browser']
|
||||
|
||||
nightly icon-browser aarch64:
|
||||
extends: '.publish_nightly'
|
||||
needs: ['flatpak:icon-browser:aarch64']
|
||||
dependencies: ['flatpak-main:icon-browser']
|
||||
needs: ['flatpak-main:icon-browser']
|
||||
|
||||
nightly node-editor:
|
||||
extends: '.publish_nightly'
|
||||
needs: ['flatpak:node-editor']
|
||||
|
||||
nightly node-editor aarch64:
|
||||
extends: '.publish_nightly'
|
||||
needs: ['flatpak:node-editor:aarch64']
|
||||
dependencies: ['flatpak-main:node-editor']
|
||||
needs: ['flatpak-main:node-editor']
|
||||
|
||||
static-scan:
|
||||
image: $FEDORA_IMAGE
|
||||
@@ -381,7 +364,6 @@ asan-build:
|
||||
tags: [ asan ]
|
||||
stage: analysis
|
||||
needs: []
|
||||
when: manual
|
||||
variables:
|
||||
script:
|
||||
- export PATH="$HOME/.local/bin:$PATH"
|
||||
@@ -436,9 +418,9 @@ reference:
|
||||
publish-docs:
|
||||
image: fedora:latest
|
||||
stage: publish
|
||||
interruptible: false
|
||||
needs: ['reference']
|
||||
script:
|
||||
- "curl -X POST -F token=${PAGES_TRIGGER_TOKEN} -F ref=docs-gtk-org https://gitlab.gnome.org/api/v4/projects/665/trigger/pipeline"
|
||||
rules:
|
||||
- if: $CI_COMMIT_REF_NAME == "main"
|
||||
only:
|
||||
refs:
|
||||
- main
|
||||
|
@@ -82,7 +82,6 @@ RUN dnf -y install \
|
||||
python3-gobject \
|
||||
python3-jinja2 \
|
||||
python3-markdown \
|
||||
python3-packaging \
|
||||
python3-pip \
|
||||
python3-pygments \
|
||||
python3-typogrify \
|
||||
|
@@ -23,7 +23,6 @@ push=0
|
||||
list=0
|
||||
print_help=0
|
||||
no_login=0
|
||||
no_cache=0
|
||||
|
||||
while (($# > 0)); do
|
||||
case "${1%%=*}" in
|
||||
@@ -35,7 +34,6 @@ while (($# > 0)); do
|
||||
--base|-b) read_arg base "$@" || shift;;
|
||||
--version|-v) read_arg base_version "$@" || shift;;
|
||||
--no-login) no_login=1;;
|
||||
--no-cache) no_cache=1;;
|
||||
*) echo -e "\e[1;31mERROR\e[0m: Unknown option '$1'"; exit 1;;
|
||||
esac
|
||||
shift
|
||||
@@ -105,21 +103,11 @@ TAG="${REGISTRY}/gnome/gtk/${base}:${base_version}"
|
||||
|
||||
if [ $build == 1 ]; then
|
||||
echo -e "\e[1;32mBUILDING\e[0m: ${base} as ${TAG}"
|
||||
if [ $no_cache == 0 ]; then
|
||||
${CMD} build \
|
||||
${format} \
|
||||
--build-arg HOST_USER_ID="$UID" \
|
||||
--tag "${TAG}" \
|
||||
--file "${base}.Dockerfile" .
|
||||
else
|
||||
${CMD} build \
|
||||
${format} \
|
||||
--no-cache \
|
||||
--build-arg HOST_USER_ID="$UID" \
|
||||
--tag "${TAG}" \
|
||||
--file "${base}.Dockerfile" .
|
||||
fi
|
||||
|
||||
${CMD} build \
|
||||
${format} \
|
||||
--build-arg HOST_USER_ID="$UID" \
|
||||
--tag "${TAG}" \
|
||||
--file "${base}.Dockerfile" .
|
||||
exit $?
|
||||
fi
|
||||
|
||||
|
@@ -21,7 +21,7 @@ many things that we value:
|
||||
Please, do not use the issue tracker for support questions. If you have
|
||||
questions on how to use GTK effectively, you can use:
|
||||
|
||||
- the `gtk` [room on matrix](https://matrix.to/#/#gtk:gnome.org)
|
||||
- the `#gtk` IRC channel on irc.gnome.org
|
||||
- the [gtk tag on the GNOME Discourse instance](https://discourse.gnome.org/tag/gtk)
|
||||
|
||||
You can also look at the GTK tag on [Stack
|
||||
@@ -44,7 +44,6 @@ If you're reporting a bug make sure to list:
|
||||
|
||||
0. which version of GTK are you using?
|
||||
0. which operating system are you using?
|
||||
0. what display and graphics driver are you using?
|
||||
0. the necessary steps to reproduce the issue
|
||||
0. the expected outcome
|
||||
0. a description of the behavior; screenshots are also welcome
|
||||
|
109
NEWS
109
NEWS
@@ -1,113 +1,6 @@
|
||||
Overview of Changes in 4.9.5, xx-xx-xxxx
|
||||
Overview of Changes in 4.9.3, xx-xx-xxxx
|
||||
========================================
|
||||
|
||||
Overview of Changes in 4.9.4, 12-02-2023
|
||||
========================================
|
||||
|
||||
* Printing:
|
||||
- Add a CPDB backend
|
||||
- Drop the lpr backend
|
||||
|
||||
* GtkFileDialog:
|
||||
- Robustness fixes
|
||||
|
||||
* GtkScaleButton:
|
||||
- Add an 'active' property
|
||||
|
||||
* GtkSearchEntry:
|
||||
- Add placeholder text
|
||||
|
||||
* Fix conflicting type names between gtk and gio
|
||||
|
||||
* Gsk:
|
||||
- Settable filtering for scaled textures
|
||||
- Add mask nodes
|
||||
- Some robustness and crash fixes
|
||||
|
||||
* Wayland:
|
||||
- Handle dispatch failing in more places
|
||||
|
||||
* Deprecations:
|
||||
- GtkVolumeButton
|
||||
|
||||
* Translation updates:
|
||||
Belarusian
|
||||
Chinese (Taiwan)
|
||||
Georgian
|
||||
Turkish
|
||||
Ukrainian
|
||||
|
||||
|
||||
Overview of Changes in 4.9.3, 04-02-2023
|
||||
========================================
|
||||
|
||||
* Add GtkUriLauncher, as replacement for gtk_show_uri
|
||||
|
||||
* Add GdkMonitor::description
|
||||
|
||||
* Fix problems with tooltip sizing
|
||||
|
||||
* Deprecations:
|
||||
- GtkStatusbar
|
||||
- GtkAssistant
|
||||
- GtkLockButton
|
||||
- gtk_gesture_set_sequence_state
|
||||
|
||||
* GtkColumnView:
|
||||
- Only create widgets for visible columns
|
||||
|
||||
* GtkFileDialog:
|
||||
- Drop shortcut folders API
|
||||
|
||||
* GtkCalendar:
|
||||
- Make marked days work again
|
||||
|
||||
* GtkSwitch:
|
||||
- Make state and active independently settable
|
||||
|
||||
* GtkFileChooser:
|
||||
- Fix a crash with DND
|
||||
- Fix excessively wide sidebar
|
||||
- Make context menus work again
|
||||
|
||||
* Accessibility:
|
||||
- Make GtkAccessible public, so it can be implemented outside GTK
|
||||
- Support accessible implementation for editables
|
||||
|
||||
* CSS:
|
||||
- Fix randomly stopping CSS animations
|
||||
|
||||
* GL:
|
||||
- Fix synchronization with GStreamer
|
||||
- Fix problems with 3rd party GL in the same thread
|
||||
|
||||
* Wayland:
|
||||
- Fix startup notification with xdg_activation
|
||||
|
||||
* Broadway:
|
||||
- Implement modal windows
|
||||
|
||||
* macOS:
|
||||
- Make DND work
|
||||
|
||||
* Build:
|
||||
- Require graphene 1.10
|
||||
- Require gobject-introspection 1.72
|
||||
|
||||
* Translation updates
|
||||
Catalan
|
||||
Galician
|
||||
German
|
||||
Hebrew
|
||||
Indonesian
|
||||
Portuguese
|
||||
Russian
|
||||
Spanish
|
||||
Swedish
|
||||
Turkish
|
||||
Ukrainian
|
||||
|
||||
|
||||
Overview of Changes in 4.9.2, 26-12-2022
|
||||
========================================
|
||||
|
||||
|
@@ -2,8 +2,6 @@
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
|
||||
typedef GtkApplication DemoApplication;
|
||||
typedef GtkApplicationClass DemoApplicationClass;
|
||||
|
||||
|
@@ -7,8 +7,6 @@
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
|
||||
static GtkWidget *progress_bar = NULL;
|
||||
|
||||
static gboolean
|
||||
|
@@ -37,8 +37,6 @@ remove_timeout (gpointer data)
|
||||
g_source_remove (id);
|
||||
}
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
|
||||
static gboolean
|
||||
pop_status (gpointer data)
|
||||
{
|
||||
@@ -59,8 +57,6 @@ status_message (GtkStatusbar *status,
|
||||
g_object_set_data_full (G_OBJECT (status), "timeout", GUINT_TO_POINTER (id), remove_timeout);
|
||||
}
|
||||
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
static void
|
||||
help_activate (GSimpleAction *action,
|
||||
GVariant *parameter,
|
||||
|
@@ -215,12 +215,6 @@
|
||||
<file>demo3widget.h</file>
|
||||
<file>demo3widget.ui</file>
|
||||
</gresource>
|
||||
<gresource prefix="/mask">
|
||||
<file>demo4widget.c</file>
|
||||
<file>demo4widget.h</file>
|
||||
<file>hsla.h</file>
|
||||
<file>hsla.c</file>
|
||||
</gresource>
|
||||
<gresource prefix="/paintable_svg">
|
||||
<file>svgpaintable.h</file>
|
||||
<file>svgpaintable.c</file>
|
||||
@@ -317,7 +311,6 @@
|
||||
<file>list_store.c</file>
|
||||
<file>main.c</file>
|
||||
<file>markup.c</file>
|
||||
<file>mask.c</file>
|
||||
<file>menu.c</file>
|
||||
<file>overlay.c</file>
|
||||
<file>overlay_decorative.c</file>
|
||||
|
@@ -3,8 +3,7 @@
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_TEXTURE = 1,
|
||||
PROP_FILTER,
|
||||
PROP_PAINTABLE = 1,
|
||||
PROP_SCALE
|
||||
};
|
||||
|
||||
@@ -12,9 +11,8 @@ struct _Demo3Widget
|
||||
{
|
||||
GtkWidget parent_instance;
|
||||
|
||||
GdkTexture *texture;
|
||||
GdkPaintable *paintable;
|
||||
float scale;
|
||||
GskScalingFilter filter;
|
||||
|
||||
GtkWidget *menu;
|
||||
};
|
||||
@@ -30,7 +28,6 @@ static void
|
||||
demo3_widget_init (Demo3Widget *self)
|
||||
{
|
||||
self->scale = 1.f;
|
||||
self->filter = GSK_SCALING_FILTER_LINEAR;
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
@@ -39,7 +36,7 @@ demo3_widget_dispose (GObject *object)
|
||||
{
|
||||
Demo3Widget *self = DEMO3_WIDGET (object);
|
||||
|
||||
g_clear_object (&self->texture);
|
||||
g_clear_object (&self->paintable);
|
||||
|
||||
gtk_widget_dispose_template (GTK_WIDGET (self), DEMO3_TYPE_WIDGET);
|
||||
|
||||
@@ -53,13 +50,12 @@ demo3_widget_snapshot (GtkWidget *widget,
|
||||
Demo3Widget *self = DEMO3_WIDGET (widget);
|
||||
int x, y, width, height;
|
||||
double w, h;
|
||||
GskRenderNode *node;
|
||||
|
||||
width = gtk_widget_get_width (widget);
|
||||
height = gtk_widget_get_height (widget);
|
||||
|
||||
w = self->scale * gdk_texture_get_width (self->texture);
|
||||
h = self->scale * gdk_texture_get_height (self->texture);
|
||||
w = self->scale * gdk_paintable_get_intrinsic_width (self->paintable);
|
||||
h = self->scale * gdk_paintable_get_intrinsic_height (self->paintable);
|
||||
|
||||
x = MAX (0, (width - ceil (w)) / 2);
|
||||
y = MAX (0, (height - ceil (h)) / 2);
|
||||
@@ -67,11 +63,7 @@ demo3_widget_snapshot (GtkWidget *widget,
|
||||
gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_INIT (0, 0, width, height));
|
||||
gtk_snapshot_save (snapshot);
|
||||
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
|
||||
node = gsk_texture_scale_node_new (self->texture,
|
||||
&GRAPHENE_RECT_INIT (0, 0, w, h),
|
||||
self->filter);
|
||||
gtk_snapshot_append_node (snapshot, node);
|
||||
gsk_render_node_unref (node);
|
||||
gdk_paintable_snapshot (self->paintable, snapshot, w, h);
|
||||
gtk_snapshot_restore (snapshot);
|
||||
gtk_snapshot_pop (snapshot);
|
||||
}
|
||||
@@ -89,9 +81,9 @@ demo3_widget_measure (GtkWidget *widget,
|
||||
int size;
|
||||
|
||||
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
size = gdk_texture_get_width (self->texture);
|
||||
size = gdk_paintable_get_intrinsic_width (self->paintable);
|
||||
else
|
||||
size = gdk_texture_get_height (self->texture);
|
||||
size = gdk_paintable_get_intrinsic_height (self->paintable);
|
||||
|
||||
*minimum = *natural = self->scale * size;
|
||||
}
|
||||
@@ -121,9 +113,9 @@ demo3_widget_set_property (GObject *object,
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_TEXTURE:
|
||||
g_clear_object (&self->texture);
|
||||
self->texture = g_value_dup_object (value);
|
||||
case PROP_PAINTABLE:
|
||||
g_clear_object (&self->paintable);
|
||||
self->paintable = g_value_dup_object (value);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (object));
|
||||
break;
|
||||
|
||||
@@ -132,11 +124,6 @@ demo3_widget_set_property (GObject *object,
|
||||
gtk_widget_queue_resize (GTK_WIDGET (object));
|
||||
break;
|
||||
|
||||
case PROP_FILTER:
|
||||
self->filter = g_value_get_enum (value);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (object));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -153,18 +140,14 @@ demo3_widget_get_property (GObject *object,
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_TEXTURE:
|
||||
g_value_set_object (value, self->texture);
|
||||
case PROP_PAINTABLE:
|
||||
g_value_set_object (value, self->paintable);
|
||||
break;
|
||||
|
||||
case PROP_SCALE:
|
||||
g_value_set_float (value, self->scale);
|
||||
break;
|
||||
|
||||
case PROP_FILTER:
|
||||
g_value_set_enum (value, self->filter);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -222,21 +205,16 @@ demo3_widget_class_init (Demo3WidgetClass *class)
|
||||
widget_class->measure = demo3_widget_measure;
|
||||
widget_class->size_allocate = demo3_widget_size_allocate;
|
||||
|
||||
g_object_class_install_property (object_class, PROP_TEXTURE,
|
||||
g_param_spec_object ("texture", NULL, NULL,
|
||||
GDK_TYPE_TEXTURE,
|
||||
g_object_class_install_property (object_class, PROP_PAINTABLE,
|
||||
g_param_spec_object ("paintable", "Paintable", "Paintable",
|
||||
GDK_TYPE_PAINTABLE,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_SCALE,
|
||||
g_param_spec_float ("scale", NULL, NULL,
|
||||
g_param_spec_float ("scale", "Scale", "Scale",
|
||||
0.0, 10.0, 1.0,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_FILTER,
|
||||
g_param_spec_enum ("filter", NULL, NULL,
|
||||
GSK_TYPE_SCALING_FILTER, GSK_SCALING_FILTER_LINEAR,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
/* These are the actions that we are using in the menu */
|
||||
gtk_widget_class_install_action (widget_class, "zoom.in", NULL, zoom_cb);
|
||||
gtk_widget_class_install_action (widget_class, "zoom.out", NULL, zoom_cb);
|
||||
@@ -251,13 +229,16 @@ GtkWidget *
|
||||
demo3_widget_new (const char *resource)
|
||||
{
|
||||
Demo3Widget *self;
|
||||
GdkTexture *texture;
|
||||
GdkPixbuf *pixbuf;
|
||||
GdkPaintable *paintable;
|
||||
|
||||
texture = gdk_texture_new_from_resource (resource);
|
||||
pixbuf = gdk_pixbuf_new_from_resource (resource, NULL);
|
||||
paintable = GDK_PAINTABLE (gdk_texture_new_for_pixbuf (pixbuf));
|
||||
|
||||
self = g_object_new (DEMO3_TYPE_WIDGET, "texture", texture, NULL);
|
||||
self = g_object_new (DEMO3_TYPE_WIDGET, "paintable", paintable, NULL);
|
||||
|
||||
g_object_unref (texture);
|
||||
g_object_unref (pixbuf);
|
||||
g_object_unref (paintable);
|
||||
|
||||
return GTK_WIDGET (self);
|
||||
}
|
||||
|
@@ -1,226 +0,0 @@
|
||||
#include <math.h>
|
||||
#include "demo4widget.h"
|
||||
#include "hsla.h"
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_PROGRESS,
|
||||
};
|
||||
|
||||
struct _Demo4Widget
|
||||
{
|
||||
GtkWidget parent_instance;
|
||||
PangoLayout *layout;
|
||||
GskColorStop stops[8];
|
||||
gsize n_stops;
|
||||
double progress;
|
||||
|
||||
guint tick;
|
||||
};
|
||||
|
||||
struct _Demo4WidgetClass
|
||||
{
|
||||
GtkWidgetClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (Demo4Widget, demo4_widget, GTK_TYPE_WIDGET)
|
||||
|
||||
static void
|
||||
rotate_color (GdkRGBA *rgba)
|
||||
{
|
||||
GdkHSLA hsla;
|
||||
|
||||
_gdk_hsla_init_from_rgba (&hsla, rgba);
|
||||
hsla.hue -= 1;
|
||||
_gdk_rgba_init_from_hsla (rgba, &hsla);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
rotate_colors (GtkWidget *widget,
|
||||
GdkFrameClock *clock,
|
||||
gpointer user_data)
|
||||
{
|
||||
Demo4Widget *self = DEMO4_WIDGET (widget);
|
||||
|
||||
for (unsigned int i = 0; i < self->n_stops; i++)
|
||||
rotate_color (&self->stops[i].color);
|
||||
|
||||
gtk_widget_queue_draw (widget);
|
||||
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
static void
|
||||
demo4_widget_init (Demo4Widget *self)
|
||||
{
|
||||
PangoFontDescription *desc;
|
||||
|
||||
self->progress = 0.5;
|
||||
|
||||
self->n_stops = 8;
|
||||
self->stops[0].offset = 0;
|
||||
self->stops[0].color = (GdkRGBA) { 1, 0, 0, 1 };
|
||||
|
||||
for (unsigned int i = 1; i < self->n_stops; i++)
|
||||
{
|
||||
GdkHSLA hsla;
|
||||
|
||||
self->stops[i].offset = i / (double)(self->n_stops - 1);
|
||||
_gdk_hsla_init_from_rgba (&hsla, &self->stops[i - 1].color);
|
||||
hsla.hue += 360.0 / (double)(self->n_stops - 1);
|
||||
_gdk_rgba_init_from_hsla (&self->stops[i].color, &hsla);
|
||||
}
|
||||
|
||||
self->layout = gtk_widget_create_pango_layout (GTK_WIDGET (self), "123");
|
||||
desc = pango_font_description_from_string ("Cantarell Bold 210");
|
||||
pango_layout_set_font_description (self->layout, desc);
|
||||
pango_font_description_free (desc);
|
||||
|
||||
self->tick = gtk_widget_add_tick_callback (GTK_WIDGET (self), rotate_colors, NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
demo4_widget_dispose (GObject *object)
|
||||
{
|
||||
Demo4Widget *self = DEMO4_WIDGET (object);
|
||||
|
||||
g_clear_object (&self->layout);
|
||||
gtk_widget_remove_tick_callback (GTK_WIDGET (self), self->tick);
|
||||
|
||||
G_OBJECT_CLASS (demo4_widget_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
demo4_widget_snapshot_content (GtkWidget *widget,
|
||||
GtkSnapshot *snapshot,
|
||||
GskMaskMode mode)
|
||||
{
|
||||
Demo4Widget *self = DEMO4_WIDGET (widget);
|
||||
int width, height, layout_width, layout_height;
|
||||
double scale;
|
||||
|
||||
width = gtk_widget_get_width (widget);
|
||||
height = gtk_widget_get_height (widget);
|
||||
|
||||
gtk_snapshot_push_mask (snapshot, mode);
|
||||
pango_layout_get_pixel_size (self->layout, &layout_width, &layout_height);
|
||||
scale = MIN ((double) width / layout_width, (double) height / layout_height);
|
||||
gtk_snapshot_translate (snapshot,
|
||||
&GRAPHENE_POINT_INIT ((width - scale * layout_width) / 2,
|
||||
(height - scale * layout_height) / 2));
|
||||
gtk_snapshot_scale (snapshot, scale, scale);
|
||||
gtk_snapshot_append_layout (snapshot, self->layout, &(GdkRGBA) { 0, 0, 0, 1 });
|
||||
gtk_snapshot_pop (snapshot);
|
||||
|
||||
gtk_snapshot_append_linear_gradient (snapshot,
|
||||
&GRAPHENE_RECT_INIT (0, 0, width, height),
|
||||
&GRAPHENE_POINT_INIT (0, 0),
|
||||
&GRAPHENE_POINT_INIT (width, height),
|
||||
self->stops,
|
||||
self->n_stops);
|
||||
gtk_snapshot_pop (snapshot);
|
||||
}
|
||||
|
||||
static void
|
||||
demo4_widget_snapshot (GtkWidget *widget,
|
||||
GtkSnapshot *snapshot)
|
||||
{
|
||||
Demo4Widget *self = DEMO4_WIDGET (widget);
|
||||
int width, height;
|
||||
|
||||
width = gtk_widget_get_width (widget);
|
||||
height = gtk_widget_get_height (widget);
|
||||
|
||||
gtk_snapshot_push_mask (snapshot, GSK_MASK_MODE_INVERTED_LUMINANCE);
|
||||
gtk_snapshot_append_linear_gradient (snapshot,
|
||||
&GRAPHENE_RECT_INIT (0, 0, width, height),
|
||||
&GRAPHENE_POINT_INIT (0, 0),
|
||||
&GRAPHENE_POINT_INIT (width, 0),
|
||||
(GskColorStop[2]) {
|
||||
{ MAX (0.0, self->progress - 5.0 / width), { 1, 1, 1, 1 } },
|
||||
{ MIN (1.0, self->progress + 5.0 / width), { 0, 0, 0, 1 } }
|
||||
}, 2);
|
||||
gtk_snapshot_pop (snapshot);
|
||||
demo4_widget_snapshot_content (widget, snapshot, GSK_MASK_MODE_INVERTED_ALPHA);
|
||||
gtk_snapshot_pop (snapshot);
|
||||
|
||||
gtk_snapshot_push_mask (snapshot, GSK_MASK_MODE_LUMINANCE);
|
||||
gtk_snapshot_append_linear_gradient (snapshot,
|
||||
&GRAPHENE_RECT_INIT (0, 0, width, height),
|
||||
&GRAPHENE_POINT_INIT (0, 0),
|
||||
&GRAPHENE_POINT_INIT (width, 0),
|
||||
(GskColorStop[2]) {
|
||||
{ MAX (0.0, self->progress - 5.0 / width), { 1, 1, 1, 1 } },
|
||||
{ MIN (1.0, self->progress + 5.0 / width), { 0, 0, 0, 1 } }
|
||||
}, 2);
|
||||
gtk_snapshot_pop (snapshot);
|
||||
demo4_widget_snapshot_content (widget, snapshot, GSK_MASK_MODE_ALPHA);
|
||||
gtk_snapshot_pop (snapshot);
|
||||
}
|
||||
|
||||
static void
|
||||
demo4_widget_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
Demo4Widget *self = DEMO4_WIDGET (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_PROGRESS:
|
||||
self->progress = g_value_get_double (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (object));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
demo4_widget_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
Demo4Widget *self = DEMO4_WIDGET (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_PROGRESS:
|
||||
g_value_set_double (value, self->progress);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
demo4_widget_class_init (Demo4WidgetClass *class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
||||
|
||||
object_class->dispose = demo4_widget_dispose;
|
||||
object_class->get_property = demo4_widget_get_property;
|
||||
object_class->set_property = demo4_widget_set_property;
|
||||
|
||||
widget_class->snapshot = demo4_widget_snapshot;
|
||||
|
||||
g_object_class_install_property (object_class, PROP_PROGRESS,
|
||||
g_param_spec_double ("progress", NULL, NULL,
|
||||
0.0, 1.0, 0.5,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
demo4_widget_new (void)
|
||||
{
|
||||
return g_object_new (DEMO4_TYPE_WIDGET, NULL);
|
||||
}
|
||||
|
@@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#define DEMO4_TYPE_WIDGET (demo4_widget_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (Demo4Widget, demo4_widget, DEMO4, WIDGET, GtkWidget)
|
||||
|
||||
GtkWidget * demo4_widget_new (void);
|
@@ -356,10 +356,6 @@ canvas_item_start_editing (CanvasItem *item)
|
||||
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
double x, y;
|
||||
} Hotspot;
|
||||
|
||||
static GdkContentProvider *
|
||||
prepare (GtkDragSource *source,
|
||||
double x,
|
||||
@@ -367,7 +363,6 @@ prepare (GtkDragSource *source,
|
||||
{
|
||||
GtkWidget *canvas;
|
||||
GtkWidget *item;
|
||||
Hotspot *hotspot;
|
||||
|
||||
canvas = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (source));
|
||||
item = gtk_widget_pick (canvas, x, y, GTK_PICK_DEFAULT);
|
||||
@@ -378,10 +373,6 @@ prepare (GtkDragSource *source,
|
||||
|
||||
g_object_set_data (G_OBJECT (canvas), "dragged-item", item);
|
||||
|
||||
hotspot = g_new (Hotspot, 1);
|
||||
gtk_widget_translate_coordinates (canvas, item, x, y, &hotspot->x, &hotspot->y);
|
||||
g_object_set_data_full (G_OBJECT (canvas), "hotspot", hotspot, g_free);
|
||||
|
||||
return gdk_content_provider_new_typed (GTK_TYPE_WIDGET, item);
|
||||
}
|
||||
|
||||
@@ -392,14 +383,12 @@ drag_begin (GtkDragSource *source,
|
||||
GtkWidget *canvas;
|
||||
CanvasItem *item;
|
||||
GdkPaintable *paintable;
|
||||
Hotspot *hotspot;
|
||||
|
||||
canvas = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (source));
|
||||
item = CANVAS_ITEM (g_object_get_data (G_OBJECT (canvas), "dragged-item"));
|
||||
hotspot = (Hotspot *) g_object_get_data (G_OBJECT (canvas), "hotspot");
|
||||
|
||||
paintable = canvas_item_get_drag_icon (item);
|
||||
gtk_drag_source_set_icon (source, paintable, hotspot->x, hotspot->y);
|
||||
gtk_drag_source_set_icon (source, paintable, item->r, item->r);
|
||||
g_object_unref (paintable);
|
||||
|
||||
gtk_widget_set_opacity (GTK_WIDGET (item), 0.3);
|
||||
|
@@ -362,7 +362,7 @@ do_drawingarea (GtkWidget *do_widget)
|
||||
G_CALLBACK (scribble_resize), NULL);
|
||||
|
||||
drag = gtk_gesture_drag_new ();
|
||||
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (drag), 0);
|
||||
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (drag), GDK_BUTTON_PRIMARY);
|
||||
gtk_widget_add_controller (da, GTK_EVENT_CONTROLLER (drag));
|
||||
|
||||
g_signal_connect (drag, "drag-begin", G_CALLBACK (drag_begin), da);
|
||||
|
@@ -48,16 +48,14 @@
|
||||
#define VERTICES_PER_TOOTH 34
|
||||
#define GEAR_VERTEX_STRIDE 6
|
||||
|
||||
static inline void
|
||||
_sincos (double x, double *_sin, double *_cos)
|
||||
#ifndef HAVE_SINCOS
|
||||
static void
|
||||
sincos (double x, double *_sin, double *_cos)
|
||||
{
|
||||
#ifdef HAVE_SINCOS
|
||||
sincos (x, _sin, _cos);
|
||||
#else
|
||||
*_sin = sin (x);
|
||||
*_cos = cos (x);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Struct describing the vertices in triangle strip
|
||||
@@ -309,11 +307,11 @@ create_gear (GLfloat inner_radius,
|
||||
struct point p[7];
|
||||
|
||||
/* Calculate needed sin/cos for various angles */
|
||||
_sincos(i * 2.0 * G_PI / teeth + da * 0, &s[0], &c[0]);
|
||||
_sincos(i * 2.0 * M_PI / teeth + da * 1, &s[1], &c[1]);
|
||||
_sincos(i * 2.0 * M_PI / teeth + da * 2, &s[2], &c[2]);
|
||||
_sincos(i * 2.0 * M_PI / teeth + da * 3, &s[3], &c[3]);
|
||||
_sincos(i * 2.0 * M_PI / teeth + da * 4, &s[4], &c[4]);
|
||||
sincos(i * 2.0 * G_PI / teeth + da * 0, &s[0], &c[0]);
|
||||
sincos(i * 2.0 * M_PI / teeth + da * 1, &s[1], &c[1]);
|
||||
sincos(i * 2.0 * M_PI / teeth + da * 2, &s[2], &c[2]);
|
||||
sincos(i * 2.0 * M_PI / teeth + da * 3, &s[3], &c[3]);
|
||||
sincos(i * 2.0 * M_PI / teeth + da * 4, &s[4], &c[4]);
|
||||
|
||||
GEAR_POINT(p[0], r2, 1);
|
||||
GEAR_POINT(p[1], r2, 2);
|
||||
@@ -522,7 +520,7 @@ void perspective(GLfloat *m, GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloa
|
||||
identity(tmp);
|
||||
|
||||
deltaZ = zFar - zNear;
|
||||
_sincos(radians, &sine, &cosine);
|
||||
sincos(radians, &sine, &cosine);
|
||||
|
||||
if ((deltaZ == 0) || (sine == 0) || (aspect == 0))
|
||||
return;
|
||||
|
@@ -1,146 +0,0 @@
|
||||
#include <gdk/gdk.h>
|
||||
#include "hsla.h"
|
||||
|
||||
void
|
||||
_gdk_hsla_init_from_rgba (GdkHSLA *hsla,
|
||||
const GdkRGBA *rgba)
|
||||
{
|
||||
float min;
|
||||
float max;
|
||||
float red;
|
||||
float green;
|
||||
float blue;
|
||||
float delta;
|
||||
|
||||
g_return_if_fail (hsla != NULL);
|
||||
g_return_if_fail (rgba != NULL);
|
||||
|
||||
red = rgba->red;
|
||||
green = rgba->green;
|
||||
blue = rgba->blue;
|
||||
|
||||
if (red > green)
|
||||
{
|
||||
if (red > blue)
|
||||
max = red;
|
||||
else
|
||||
max = blue;
|
||||
|
||||
if (green < blue)
|
||||
min = green;
|
||||
else
|
||||
min = blue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (green > blue)
|
||||
max = green;
|
||||
else
|
||||
max = blue;
|
||||
|
||||
if (red < blue)
|
||||
min = red;
|
||||
else
|
||||
min = blue;
|
||||
}
|
||||
|
||||
hsla->lightness = (max + min) / 2;
|
||||
hsla->saturation = 0;
|
||||
hsla->hue = 0;
|
||||
hsla->alpha = rgba->alpha;
|
||||
|
||||
if (max != min)
|
||||
{
|
||||
if (hsla->lightness <= 0.5)
|
||||
hsla->saturation = (max - min) / (max + min);
|
||||
else
|
||||
hsla->saturation = (max - min) / (2 - max - min);
|
||||
|
||||
delta = max -min;
|
||||
if (red == max)
|
||||
hsla->hue = (green - blue) / delta;
|
||||
else if (green == max)
|
||||
hsla->hue = 2 + (blue - red) / delta;
|
||||
else if (blue == max)
|
||||
hsla->hue = 4 + (red - green) / delta;
|
||||
|
||||
hsla->hue *= 60;
|
||||
if (hsla->hue < 0.0)
|
||||
hsla->hue += 360;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_rgba_init_from_hsla (GdkRGBA *rgba,
|
||||
const GdkHSLA *hsla)
|
||||
{
|
||||
float hue;
|
||||
float lightness;
|
||||
float saturation;
|
||||
float m1, m2;
|
||||
|
||||
lightness = hsla->lightness;
|
||||
saturation = hsla->saturation;
|
||||
|
||||
if (lightness <= 0.5)
|
||||
m2 = lightness * (1 + saturation);
|
||||
else
|
||||
m2 = lightness + saturation - lightness * saturation;
|
||||
m1 = 2 * lightness - m2;
|
||||
|
||||
rgba->alpha = hsla->alpha;
|
||||
|
||||
if (saturation == 0)
|
||||
{
|
||||
rgba->red = lightness;
|
||||
rgba->green = lightness;
|
||||
rgba->blue = lightness;
|
||||
}
|
||||
else
|
||||
{
|
||||
hue = hsla->hue + 120;
|
||||
while (hue > 360)
|
||||
hue -= 360;
|
||||
while (hue < 0)
|
||||
hue += 360;
|
||||
|
||||
if (hue < 60)
|
||||
rgba->red = m1 + (m2 - m1) * hue / 60;
|
||||
else if (hue < 180)
|
||||
rgba->red = m2;
|
||||
else if (hue < 240)
|
||||
rgba->red = m1 + (m2 - m1) * (240 - hue) / 60;
|
||||
else
|
||||
rgba->red = m1;
|
||||
|
||||
hue = hsla->hue;
|
||||
while (hue > 360)
|
||||
hue -= 360;
|
||||
while (hue < 0)
|
||||
hue += 360;
|
||||
|
||||
if (hue < 60)
|
||||
rgba->green = m1 + (m2 - m1) * hue / 60;
|
||||
else if (hue < 180)
|
||||
rgba->green = m2;
|
||||
else if (hue < 240)
|
||||
rgba->green = m1 + (m2 - m1) * (240 - hue) / 60;
|
||||
else
|
||||
rgba->green = m1;
|
||||
|
||||
hue = hsla->hue - 120;
|
||||
while (hue > 360)
|
||||
hue -= 360;
|
||||
while (hue < 0)
|
||||
hue += 360;
|
||||
|
||||
if (hue < 60)
|
||||
rgba->blue = m1 + (m2 - m1) * hue / 60;
|
||||
else if (hue < 180)
|
||||
rgba->blue = m2;
|
||||
else if (hue < 240)
|
||||
rgba->blue = m1 + (m2 - m1) * (240 - hue) / 60;
|
||||
else
|
||||
rgba->blue = m1;
|
||||
}
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
typedef struct _GdkHSLA GdkHSLA;
|
||||
|
||||
struct _GdkHSLA {
|
||||
float hue;
|
||||
float saturation;
|
||||
float lightness;
|
||||
float alpha;
|
||||
};
|
||||
|
||||
void _gdk_hsla_init_from_rgba (GdkHSLA *hsla,
|
||||
const GdkRGBA *rgba);
|
||||
void _gdk_rgba_init_from_hsla (GdkRGBA *rgba,
|
||||
const GdkHSLA *hsla);
|
@@ -1,53 +0,0 @@
|
||||
/* Masking
|
||||
*
|
||||
* Demonstrates mask nodes.
|
||||
*
|
||||
* This demo uses a text node as mask for
|
||||
* an animated linear gradient.
|
||||
*/
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "demo4widget.h"
|
||||
|
||||
|
||||
GtkWidget *
|
||||
do_mask (GtkWidget *do_widget)
|
||||
{
|
||||
static GtkWidget *window = NULL;
|
||||
|
||||
if (!window)
|
||||
{
|
||||
GtkWidget *box;
|
||||
GtkWidget *demo;
|
||||
GtkWidget *scale;
|
||||
|
||||
window = gtk_window_new ();
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Mask Nodes");
|
||||
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
|
||||
gtk_window_set_display (GTK_WINDOW (window),
|
||||
gtk_widget_get_display (do_widget));
|
||||
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
||||
|
||||
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
gtk_window_set_child (GTK_WINDOW (window), box);
|
||||
|
||||
demo = demo4_widget_new ();
|
||||
gtk_widget_set_hexpand (demo, TRUE);
|
||||
gtk_widget_set_vexpand (demo, TRUE);
|
||||
|
||||
gtk_box_append (GTK_BOX (box), demo);
|
||||
|
||||
scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0, 1, 0.1);
|
||||
gtk_range_set_value (GTK_RANGE (scale), 0.5);
|
||||
g_object_bind_property (gtk_range_get_adjustment (GTK_RANGE (scale)), "value", demo, "progress", 0);
|
||||
|
||||
gtk_box_append (GTK_BOX (box), scale);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
gtk_widget_set_visible (window, TRUE);
|
||||
else
|
||||
gtk_window_destroy (GTK_WINDOW (window));
|
||||
|
||||
return window;
|
||||
}
|
@@ -22,11 +22,9 @@ do_menu (GtkWidget *do_widget)
|
||||
if (!window)
|
||||
{
|
||||
GtkWidget *box;
|
||||
GtkWidget *box2;
|
||||
GtkWidget *sw;
|
||||
GtkWidget *widget;
|
||||
GtkWidget *scale;
|
||||
GtkWidget *dropdown;
|
||||
|
||||
window = gtk_window_new ();
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Menu");
|
||||
@@ -45,19 +43,10 @@ do_menu (GtkWidget *do_widget)
|
||||
widget = demo3_widget_new ("/transparent/portland-rose.jpg");
|
||||
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), widget);
|
||||
|
||||
box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
||||
gtk_box_append (GTK_BOX (box), box2);
|
||||
|
||||
scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0.01, 10.0, 0.1);
|
||||
gtk_range_set_value (GTK_RANGE (scale), 1.0);
|
||||
gtk_widget_set_hexpand (scale, TRUE);
|
||||
gtk_box_append (GTK_BOX (box2), scale);
|
||||
gtk_box_append (GTK_BOX (box), scale);
|
||||
|
||||
dropdown = gtk_drop_down_new (G_LIST_MODEL (gtk_string_list_new ((const char *[]){ "Linear", "Nearest", "Trilinear", NULL })), NULL);
|
||||
gtk_box_append (GTK_BOX (box2), dropdown);
|
||||
|
||||
g_object_bind_property (dropdown, "selected", widget, "filter", G_BINDING_DEFAULT);
|
||||
|
||||
g_object_bind_property (gtk_range_get_adjustment (GTK_RANGE (scale)), "value",
|
||||
widget, "scale",
|
||||
G_BINDING_BIDIRECTIONAL);
|
||||
|
@@ -46,7 +46,6 @@ demos = files([
|
||||
'links.c',
|
||||
'listbox.c',
|
||||
'listbox_controls.c',
|
||||
'mask.c',
|
||||
'menu.c',
|
||||
'flowbox.c',
|
||||
'list_store.c',
|
||||
@@ -115,7 +114,6 @@ extra_demo_sources = files([
|
||||
'gtkshadertoy.c',
|
||||
'gtkshaderstack.c',
|
||||
'gskshaderpaintable.c',
|
||||
'hsla.c',
|
||||
'puzzlepiece.c',
|
||||
'bluroverlay.c',
|
||||
'demoimage.c',
|
||||
@@ -128,7 +126,6 @@ extra_demo_sources = files([
|
||||
'four_point_transform.c',
|
||||
'demo2widget.c',
|
||||
'demo3widget.c',
|
||||
'demo4widget.c',
|
||||
'pixbufpaintable.c',
|
||||
'script-names.c',
|
||||
'unicode-names.c',
|
||||
|
@@ -178,16 +178,6 @@ Creates a node like `gsk_inset_shadow_node_new()` with the given properties.
|
||||
|
||||
Creates a node like `gsk_linear_gradient_node_new()` with the given properties.
|
||||
|
||||
### mask
|
||||
|
||||
| property | syntax | default | printed |
|
||||
| -------- | ---------------- | ---------------------- | ----------- |
|
||||
| source | `<node>` | color { } | always |
|
||||
| mode | `<blend-mode>` | alpha | non-default |
|
||||
| mask | `<node>` | color { } | always |
|
||||
|
||||
Creates a node like `gsk_mask_node_new()` with the given properties.
|
||||
|
||||
### opacity
|
||||
|
||||
| property | syntax | default | printed |
|
||||
@@ -307,21 +297,6 @@ The default texture is a 10x10 checkerboard with the top left and bottom right
|
||||
representation for this texture is `url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABmJLR0QA/wD/AP+gvaeTAAAAKUlEQVQYlWP8z3DmPwMaYGQwYUQXY0IXwAUGUCGGoxkYGBiweXAoeAYAz44F3e3U1xUAAAAASUVORK5CYII=")
|
||||
`.
|
||||
|
||||
### texture-scale
|
||||
|
||||
| property | syntax | default | printed |
|
||||
| -------- | ---------------- | ---------------------- | ----------- |
|
||||
| bounds | `<rect>` | 50 | always |
|
||||
| texture | `<url>` | *see below* | always |
|
||||
| filter | `filter` | *see below* | non-default |
|
||||
|
||||
Creates a node like `gsk_texture_scale_node_new()` with the given properties.
|
||||
|
||||
The default texture is a 10x10 checkerboard, just like for texture.
|
||||
|
||||
The possible filter values are `linear`, `nearest` and `trilinear`, with
|
||||
`linear` being the default.
|
||||
|
||||
### transform
|
||||
|
||||
| property | syntax | default | printed |
|
||||
|
@@ -6,8 +6,6 @@
|
||||
|
||||
#include "demo_conf.h"
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
|
||||
static GtkWidget *main_window;
|
||||
static GFile *filename = NULL;
|
||||
static GtkPageSetup *page_setup = NULL;
|
||||
|
@@ -2252,13 +2252,11 @@ activate (GApplication *app)
|
||||
for (i = 0; i < G_N_ELEMENTS (accels); i++)
|
||||
gtk_application_set_accels_for_action (GTK_APPLICATION (app), accels[i].action_and_target, accels[i].accelerators);
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
widget = (GtkWidget *)gtk_builder_get_object (builder, "statusbar");
|
||||
gtk_statusbar_push (GTK_STATUSBAR (widget), 0, "All systems are operating normally.");
|
||||
action = G_ACTION (g_property_action_new ("statusbar", widget, "visible"));
|
||||
g_action_map_add_action (G_ACTION_MAP (window), action);
|
||||
g_object_unref (G_OBJECT (action));
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
widget = (GtkWidget *)gtk_builder_get_object (builder, "toolbar");
|
||||
action = G_ACTION (g_property_action_new ("toolbar", widget, "visible"));
|
||||
@@ -2432,7 +2430,6 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
widget = (GtkWidget *)gtk_builder_get_object (builder, "record_button");
|
||||
g_object_set_data (G_OBJECT (window), "record_button", widget);
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
widget = (GtkWidget *)gtk_builder_get_object (builder, "lockbox");
|
||||
widget2 = (GtkWidget *)gtk_builder_get_object (builder, "lockbutton");
|
||||
g_object_set_data (G_OBJECT (window), "lockbutton", widget2);
|
||||
@@ -2450,7 +2447,6 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
G_BINDING_SYNC_CREATE);
|
||||
gtk_lock_button_set_permission (GTK_LOCK_BUTTON (widget2), permission);
|
||||
g_object_unref (permission);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
widget = (GtkWidget *)gtk_builder_get_object (builder, "iconview1");
|
||||
widget2 = (GtkWidget *)gtk_builder_get_object (builder, "increase_button");
|
||||
|
@@ -239,14 +239,14 @@ control whether Vulkan should be used.
|
||||
### `media-gstreamer` and `media-ffmpeg`
|
||||
|
||||
By default, GTK will try to build the gstreamer backend for
|
||||
media playback support. These options can be used to explicitly
|
||||
media playback support. These option can be used to explicitly
|
||||
control which media backends should be built.
|
||||
|
||||
### `print-cups` and `print-cpdb`
|
||||
### `print-cups`
|
||||
|
||||
By default, GTK will try to build the cups and file print backends
|
||||
if their dependencies are found. These options can be used to
|
||||
explicitly control which print backends should be built.
|
||||
By default, GTK will try to build various print backends
|
||||
if their dependencies are found. This option can be used
|
||||
to explicitly control whether the cups print backend should be built.
|
||||
|
||||
### `cloudproviders`
|
||||
|
||||
|
@@ -33,11 +33,6 @@ Validation
|
||||
The ``validate`` command validates the given UI definition file and reports
|
||||
errors to ``stderr``.
|
||||
|
||||
Note that there are limitations to the validation that can be done for templates,
|
||||
since they are closely tied to the class_init function they are used in.
|
||||
If your UI file uses types from third-party libraries, it may help to add those
|
||||
libraries to the `LD_PRELOAD` environment variable.
|
||||
|
||||
``--deprecations``
|
||||
|
||||
Warn about uses of deprecated types in the UI definition file.
|
||||
|
@@ -109,13 +109,3 @@ Other libraries, such as libadwaita, may provide replacements as well.
|
||||
## gtk_show_uri is being replaced
|
||||
|
||||
Instead of gtk_show_uri(), you should use GtkUriLauncher or GtkFileLauncher.
|
||||
|
||||
## GtkStatusbar is going away
|
||||
|
||||
This is an oldfashioned widget that does not do all that much anymore, since
|
||||
it no longer has a resize handle for the window.
|
||||
|
||||
## GtkLockButton and GtkVolumeButton are going away
|
||||
|
||||
These are very specialized widgets that should better live with the application
|
||||
where they are used.
|
||||
|
@@ -7,50 +7,37 @@ the question you have, this list is a good place to start.
|
||||
|
||||
## General Questions
|
||||
|
||||
* How do I get started with GTK?
|
||||
1. How do I get started with GTK?
|
||||
|
||||
The GTK [website](https://www.gtk.org) offers some
|
||||
[tutorials](https://www.gtk.org/documentation.php) and other documentation
|
||||
This reference manual also contains a introductory
|
||||
(most of it about GTK 2.x and 3.x, but still somewhat applicable). This
|
||||
reference manual also contains a introductory
|
||||
[Getting Started](#gtk-getting-started) part.
|
||||
|
||||
More documentation ranging from whitepapers to online books can be found at
|
||||
the [GNOME developer's site](https://developer.gnome.org). After studying these
|
||||
materials you should be well prepared to come back to this reference manual for details.
|
||||
|
||||
* Where can I get help with GTK, submit a bug report, or make a feature request?
|
||||
2. Where can I get help with GTK, submit a bug report, or make a feature request?
|
||||
|
||||
See the [documentation](#gtk-resources) on this topic.
|
||||
|
||||
* How do I port from one GTK version to another?
|
||||
3. How do I port from one GTK version to another?
|
||||
|
||||
Every major version of GTK comes with a [migration guide](#migrating). You may also
|
||||
find useful information in the documentation for specific widgets and functions. If
|
||||
you have a question not covered in the manual, feel free to ask, and please
|
||||
See the [migration guide](#migrating). You may also find useful information in
|
||||
the documentation for specific widgets and functions. If you have a question not
|
||||
covered in the manual, feel free to ask, and please
|
||||
[file a bug report](https://gitlab.gnome.org/GNOME/gtk/issues/new) against the
|
||||
documentation.
|
||||
|
||||
* Should I maintain parallel versions of my UI in GTK x and GTK y?
|
||||
|
||||
At the end of the day, that is up to you.
|
||||
|
||||
Our experience is that it is a lot of work, and usually not a good idea.
|
||||
|
||||
If you are not ready to make the jump to the next major version of GTK,
|
||||
it is perfectly fine to stick with the stable release. We maintain them
|
||||
for that reason.
|
||||
|
||||
* How does memory management work in GTK? Should I free data returned from functions?
|
||||
4. How does memory management work in GTK? Should I free data returned from functions?
|
||||
|
||||
See the documentation for `GObject` and `GInitiallyUnowned`. For `GObject` note
|
||||
specifically `g_object_ref()` and `g_object_unref()`. `GInitiallyUnowned` is a
|
||||
subclass of `GObject` so the same points apply, except that it has a "floating"
|
||||
state (explained in its documentation).
|
||||
|
||||
In a widget tree, each container owns a reference to its children. The root
|
||||
object (typically a `GtkWindow`) is owned by GTK. GTK will drop its reference
|
||||
when you call [method@Gtk.Window.destroy].
|
||||
|
||||
For strings returned from functions, they will be declared "const" if they should
|
||||
not be freed. Non-const strings should be freed with `g_free()`. Arrays follow the
|
||||
same rule. If you find an undocumented exception to the rules, please
|
||||
@@ -59,7 +46,7 @@ the question you have, this list is a good place to start.
|
||||
The transfer annotations for gobject-introspection that are part of the
|
||||
documentation can provide useful hints for memory handling semantics as well.
|
||||
|
||||
* Why does my program leak memory, if I destroy a widget immediately
|
||||
5. Why does my program leak memory, if I destroy a widget immediately
|
||||
after creating it?
|
||||
|
||||
If `GtkFoo` isn't a toplevel window, then
|
||||
@@ -82,7 +69,7 @@ the question you have, this list is a good place to start.
|
||||
the initial floating reference and you don't have to worry about reference
|
||||
counting at all ... just remove the widget from the container to get rid of it.
|
||||
|
||||
* How do I use GTK with threads?
|
||||
6. How do I use GTK with threads?
|
||||
|
||||
GTK requires that all GTK API calls are made from the same thread in which
|
||||
the `GtkApplication` was created, or `gtk_init()` was called (the _main thread_).
|
||||
@@ -92,7 +79,7 @@ the question you have, this list is a good place to start.
|
||||
the results back to the main thread using `g_idle_add()` or `GAsyncQueue`. GIO
|
||||
offers useful tools for such an approach such as `GTask`.
|
||||
|
||||
* How do I internationalize a GTK program?
|
||||
7. How do I internationalize a GTK program?
|
||||
|
||||
Most people use [GNU gettext](https://www.gnu.org/software/gettext/),
|
||||
already required in order to install GLib. On a UNIX or Linux system with
|
||||
@@ -147,7 +134,7 @@ the question you have, this list is a good place to start.
|
||||
|
||||
#define _(x) dgettext (GETTEXT_PACKAGE, x)
|
||||
|
||||
* How do I use non-ASCII characters in GTK programs ?
|
||||
8. How do I use non-ASCII characters in GTK programs ?
|
||||
|
||||
GTK uses [Unicode](http://www.unicode.org) (more exactly UTF-8) for all text.
|
||||
UTF-8 encodes each Unicode codepoint as a sequence of one to six bytes and
|
||||
@@ -230,7 +217,7 @@ the question you have, this list is a good place to start.
|
||||
to call bind_textdomain_codeset() to ensure that translated strings
|
||||
are returned in UTF-8 encoding.
|
||||
|
||||
* How do I use GTK with C++?
|
||||
9. How do I use GTK with C++?
|
||||
|
||||
There are two ways to approach this. The GTK header files use the subset
|
||||
of C that's also valid C++, so you can simply use the normal GTK API
|
||||
@@ -255,23 +242,19 @@ the question you have, this list is a good place to start.
|
||||
|
||||
There are very few functions that require this cast, however.
|
||||
|
||||
* How do I use GTK with other non-C languages?
|
||||
10. How do I use GTK with other non-C languages?
|
||||
|
||||
See the list of [language bindings](https://www.gtk.org/language-bindings.php)
|
||||
on the GTK [website](https://www.gtk.org).
|
||||
|
||||
* How do I load an image or animation from a file?
|
||||
11. How do I load an image or animation from a file?
|
||||
|
||||
To load an image file straight into a display widget, use
|
||||
[ctor@Gtk.Picture.new_for_file] or [ctor@GTk.Picture.new_for_filename].
|
||||
To load an image for another purpose, use [ctor@Gdk.Texture.new_from_file].
|
||||
To load a video from a file, use [ctor@Gtk.MediaFile.new_for_file].
|
||||
[ctor@Gtk.Image.new_from_file]. To load an image for another purpose, use
|
||||
[ctor@Gdk.Texture.new_from_file]. To load a video from a file, use
|
||||
[ctor@Gtk.MediaFile.new_for_file].
|
||||
|
||||
* How do I draw text?
|
||||
|
||||
If you just want to put text into your user interface somewhere, it is
|
||||
usually easiest to just use one of ready-made widgets for this purpose,
|
||||
such as [class@Gtk.Label].
|
||||
12. How do I draw text?
|
||||
|
||||
To draw a piece of text onto a cairo surface, use a Pango layout and
|
||||
[func@PangoCairo.show_layout].
|
||||
@@ -289,7 +272,7 @@ the question you have, this list is a good place to start.
|
||||
To draw a piece of text in a widget [vfunc@Gtk.Widget.snapshot] implementation,
|
||||
use [method@Gtk.Snapshot.append_layout].
|
||||
|
||||
* How do I measure the size of a piece of text?
|
||||
13. How do I measure the size of a piece of text?
|
||||
|
||||
To obtain the size of a piece of text, use a Pango layout and
|
||||
[method@Pango.Layout.get_pixel_size], using code like the following:
|
||||
@@ -304,7 +287,7 @@ the question you have, this list is a good place to start.
|
||||
See also the [Layout Objects](https://developer.gnome.org/pango/stable/pango-Layout-Objects.html)
|
||||
section of the [Pango documentation](https://developer.gnome.org/pango/stable/).
|
||||
|
||||
* Why are types not registered if I use their `GTK_TYPE_BLAH` macro?
|
||||
14. Why are types not registered if I use their `GTK_TYPE_BLAH` macro?
|
||||
|
||||
The %GTK_TYPE_BLAH macros are defined as calls to gtk_blah_get_type(), and
|
||||
the `_get_type()` functions are declared as %G_GNUC_CONST which allows the
|
||||
@@ -315,14 +298,14 @@ the question you have, this list is a good place to start.
|
||||
|
||||
g_type_ensure (GTK_TYPE_BLAH);
|
||||
|
||||
* How do I create a transparent toplevel window?
|
||||
15. How do I create a transparent toplevel window?
|
||||
|
||||
Any toplevel window can be transparent. It is just a matter of setting a
|
||||
transparent background in the CSS style for it.
|
||||
|
||||
## Which widget should I use...
|
||||
|
||||
* ...for lists and trees?
|
||||
16. ...for lists and trees?
|
||||
|
||||
This question has different answers, depending on the size of the dataset
|
||||
and the required formatting flexibility.
|
||||
@@ -338,7 +321,7 @@ the question you have, this list is a good place to start.
|
||||
and widgetry inside the list, then you probably want to use a [class@Gtk.ListBox],
|
||||
which uses regular widgets for display.
|
||||
|
||||
* ...for multi-line text display or editing?
|
||||
17. ...for multi-line text display or editing?
|
||||
|
||||
See the [text widget overview](#TextWidget) -- you should use the
|
||||
[class@Gtk.TextView] widget.
|
||||
@@ -347,7 +330,7 @@ the question you have, this list is a good place to start.
|
||||
of course. It can be made selectable with [method@Gtk.Label.set_selectable]. For a
|
||||
single-line text entry, see [class@Gtk.Entry].
|
||||
|
||||
* ...to display an image or animation?
|
||||
18. ...to display an image or animation?
|
||||
|
||||
GTK has two widgets that are dedicated to displaying images. [class@Gtk.Image], for
|
||||
small, fixed-size icons and [class@Gtk.Picture] for content images.
|
||||
@@ -363,14 +346,17 @@ the question you have, this list is a good place to start.
|
||||
mediafile = gtk_media_file_new_for_filename ("example.webm");
|
||||
picture = gtk_picture_new_for_paintable (GDK_PAINTABLE (mediafile));
|
||||
|
||||
* ...for presenting a set of mutually-exclusive choices, where Windows
|
||||
19. ...for presenting a set of mutually-exclusive choices, where Windows
|
||||
would use a combo box?
|
||||
|
||||
With GTK, a [class@Gtk.DropDown] is the recommended widget to use for this use case.
|
||||
With GTK, a [class@Gtk.ComboBox] is the recommended widget to use for this use case.
|
||||
If you need an editable text entry, use the [property@Gtk.ComboBox:has-entry] property.
|
||||
|
||||
A newer alternative is [class@Gtk.DropDown].
|
||||
|
||||
## Questions about GtkWidget
|
||||
|
||||
* How do I change the color of a widget?
|
||||
20. How do I change the color of a widget?
|
||||
|
||||
The background color of a widget is determined by the CSS style that applies
|
||||
to it. To change that, you can set style classes on the widget, and provide
|
||||
@@ -378,7 +364,7 @@ the question you have, this list is a good place to start.
|
||||
[method@Gtk.CssProvider.load_from_file] and its variants.
|
||||
See [method@Gtk.StyleContext.add_provider].
|
||||
|
||||
* How do I change the font of a widget?
|
||||
21. How do I change the font of a widget?
|
||||
|
||||
If you want to make the text of a label larger, you can use
|
||||
gtk_label_set_markup():
|
||||
@@ -402,14 +388,14 @@ the question you have, this list is a good place to start.
|
||||
of this approach is that users can then override the font you have chosen.
|
||||
See the `GtkStyleContext` documentation for more discussion.
|
||||
|
||||
* How do I disable/ghost/desensitize a widget?
|
||||
22. How do I disable/ghost/desensitize a widget?
|
||||
|
||||
In GTK a disabled widget is termed _insensitive_.
|
||||
See [method@Gtk.Widget.set_sensitive].
|
||||
|
||||
## GtkTextView questions
|
||||
|
||||
* How do I get the contents of the entire text widget as a string?
|
||||
23. How do I get the contents of the entire text widget as a string?
|
||||
|
||||
See [method@Gtk.TextBuffer.get_bounds] and [method@Gtk.TextBuffer.get_text]
|
||||
or [method@Gtk.TextIter.get_text].
|
||||
@@ -424,14 +410,14 @@ the question you have, this list is a good place to start.
|
||||
/* use text */
|
||||
g_free (text);
|
||||
|
||||
* How do I make a text widget display its complete contents in a specific font?
|
||||
24. How do I make a text widget display its complete contents in a specific font?
|
||||
|
||||
If you use [method@Gtk.TextBuffer.insert_with_tags] with appropriate tags to
|
||||
select the font, the inserted text will have the desired appearance, but
|
||||
text typed in by the user before or after the tagged block will appear in
|
||||
the default style.
|
||||
|
||||
* How do I make a text view scroll to the end of the buffer automatically ?
|
||||
25. How do I make a text view scroll to the end of the buffer automatically ?
|
||||
|
||||
A good way to keep a text buffer scrolled to the end is to place a
|
||||
[mark](#GtkTextMark) at the end of the buffer, and give it right gravity.
|
||||
@@ -446,21 +432,21 @@ the question you have, this list is a good place to start.
|
||||
|
||||
## GtkTreeView questions
|
||||
|
||||
* How do I associate some data with a row in the tree?
|
||||
26. How do I associate some data with a row in the tree?
|
||||
|
||||
Remember that the [iface@Gtk.TreeModel] columns don't necessarily have to be
|
||||
displayed. So you can put non-user-visible data in your model just
|
||||
like any other data, and retrieve it with [method@Gtk.TreeModel.get].
|
||||
See the [tree widget overview](#TreeWidget).
|
||||
|
||||
* How do I put an image and some text in the same column?
|
||||
27. How do I put an image and some text in the same column?
|
||||
|
||||
You can pack more than one [class@Gtk.CellRenderer] into a single [class@Gtk.TreeViewColumn]
|
||||
using [method@Gtk.TreeViewColumn.pack_start] or [method@Gtk.TreeViewColumn.pack_end].
|
||||
So pack both a [class@Gtk.CellRendererPixbuf] and a [class@Gtk.CellRendererText] into the
|
||||
column.
|
||||
|
||||
* I can set data easily on my [class@Gtk.TreeStore] or [class@Gtk.ListStore] models using
|
||||
28. I can set data easily on my [class@Gtk.TreeStore] or [class@Gtk.ListStore] models using
|
||||
[method@Gtk.ListStore.set] and [method@Gtk.TreeStore.set], but can't read it back?
|
||||
|
||||
Both the [class@Gtk.TreeStore] and the [class@Gtk.ListStore] implement the [iface@Gtk.TreeModel]
|
||||
@@ -468,7 +454,7 @@ the question you have, this list is a good place to start.
|
||||
implements. The easiest way to read a set of data back is to use
|
||||
[method@Gtk.TreeModel.get].
|
||||
|
||||
* How do I change the way that numbers are formatted by `GtkTreeView`?
|
||||
29. How do I change the way that numbers are formatted by `GtkTreeView`?
|
||||
|
||||
Use [method@Gtk.TreeView.insert_column_with_data_func] or
|
||||
[method@Gtk.TreeViewColumn.set_cell_data_func] and do the conversion
|
||||
@@ -542,21 +528,19 @@ the question you have, this list is a good place to start.
|
||||
(gpointer)DOUBLE_COLUMN, NULL);
|
||||
}
|
||||
|
||||
* How do I hide the expander arrows in my tree view?
|
||||
30. How do I hide the expander arrows in my tree view?
|
||||
|
||||
Set the expander-column property of the tree view to a hidden column.
|
||||
See [method@Gtk.TreeView.set_expander_column] and [method@Gtk.TreeViewColumn.set_visible].
|
||||
|
||||
## Using cairo with GTK
|
||||
|
||||
* How do I use cairo to draw in GTK applications?
|
||||
31. How do I use cairo to draw in GTK applications?
|
||||
|
||||
[class@Gtk.DrawingArea] is a ready-made widget for drawing with cairo.
|
||||
Use [method@Gtk.Snapshot.append_cairo] in your [vfunc@Gtk.Widget.snapshot] vfunc
|
||||
to obtain a cairo context and draw with that.
|
||||
|
||||
If you implement a custom widget, use [method@Gtk.Snapshot.append_cairo]
|
||||
in your [vfunc@Gtk.Widget.snapshot] vfunc to obtain a cairo context and draw with that.
|
||||
|
||||
* Can I improve the performance of my application by using another backend
|
||||
32. Can I improve the performance of my application by using another backend
|
||||
of cairo (such as GL)?
|
||||
|
||||
No. Most drawing in GTK is not done via cairo anymore (but instead
|
||||
@@ -567,7 +551,7 @@ the question you have, this list is a good place to start.
|
||||
|
||||
If you are interested in using GL for your own drawing, see [class@Gtk.GLArea].
|
||||
|
||||
* Can I use cairo to draw on a `GdkPixbuf`?
|
||||
33. Can I use cairo to draw on a `GdkPixbuf`?
|
||||
|
||||
No. The cairo image surface does not support the pixel format used by `GdkPixbuf`.
|
||||
|
||||
|
@@ -37,7 +37,7 @@ main (int argc,
|
||||
GtkApplication *app;
|
||||
int status;
|
||||
|
||||
app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
|
||||
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
|
||||
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
||||
status = g_application_run (G_APPLICATION (app), argc, argv);
|
||||
g_object_unref (app);
|
||||
|
@@ -213,7 +213,6 @@ typedef enum {
|
||||
BROADWAY_REQUEST_RELEASE_TEXTURE,
|
||||
BROADWAY_REQUEST_SET_NODES,
|
||||
BROADWAY_REQUEST_ROUNDTRIP,
|
||||
BROADWAY_REQUEST_SET_MODAL_HINT,
|
||||
} BroadwayRequestType;
|
||||
|
||||
typedef struct {
|
||||
@@ -294,12 +293,6 @@ typedef struct {
|
||||
guint32 show_keyboard;
|
||||
} BroadwayRequestSetShowKeyboard;
|
||||
|
||||
typedef struct {
|
||||
BroadwayRequestBase base;
|
||||
guint32 id;
|
||||
gboolean modal_hint;
|
||||
} BroadwayRequestSetModalHint;
|
||||
|
||||
typedef union {
|
||||
BroadwayRequestBase base;
|
||||
BroadwayRequestNewSurface new_surface;
|
||||
@@ -319,7 +312,6 @@ typedef union {
|
||||
BroadwayRequestUploadTexture upload_texture;
|
||||
BroadwayRequestReleaseTexture release_texture;
|
||||
BroadwayRequestSetNodes set_nodes;
|
||||
BroadwayRequestSetModalHint set_modal_hint;
|
||||
} BroadwayRequest;
|
||||
|
||||
typedef enum {
|
||||
|
@@ -124,7 +124,6 @@ struct BroadwaySurface {
|
||||
gboolean visible;
|
||||
gint32 transient_for;
|
||||
guint32 texture;
|
||||
gboolean modal_hint;
|
||||
BroadwayNode *nodes;
|
||||
GHashTable *node_lookup;
|
||||
};
|
||||
@@ -422,14 +421,6 @@ update_event_state (BroadwayServer *server,
|
||||
{
|
||||
surface->x = message->configure_notify.x;
|
||||
surface->y = message->configure_notify.y;
|
||||
|
||||
if (server->focused_surface_id != message->configure_notify.id &&
|
||||
server->pointer_grab_surface_id == -1 && surface->modal_hint)
|
||||
{
|
||||
broadway_server_surface_raise (server, message->configure_notify.id);
|
||||
broadway_server_focus_surface (server, message->configure_notify.id);
|
||||
broadway_server_flush (server);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BROADWAY_EVENT_ROUNDTRIP_NOTIFY:
|
||||
@@ -1577,7 +1568,6 @@ broadway_server_destroy_surface (BroadwayServer *server,
|
||||
int id)
|
||||
{
|
||||
BroadwaySurface *surface;
|
||||
gint32 transient_for = -1;
|
||||
|
||||
if (server->mouse_in_surface_id == id)
|
||||
{
|
||||
@@ -1595,24 +1585,11 @@ broadway_server_destroy_surface (BroadwayServer *server,
|
||||
surface = broadway_server_lookup_surface (server, id);
|
||||
if (surface != NULL)
|
||||
{
|
||||
if (server->focused_surface_id == id)
|
||||
transient_for = surface->transient_for;
|
||||
|
||||
server->surfaces = g_list_remove (server->surfaces, surface);
|
||||
g_hash_table_remove (server->surface_id_hash,
|
||||
GINT_TO_POINTER (id));
|
||||
broadway_surface_free (server, surface);
|
||||
}
|
||||
|
||||
if (transient_for != -1)
|
||||
{
|
||||
surface = broadway_server_lookup_surface (server, transient_for);
|
||||
if (surface != NULL)
|
||||
{
|
||||
broadway_server_focus_surface (server, transient_for);
|
||||
broadway_server_flush (server);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
@@ -1733,19 +1710,6 @@ broadway_server_surface_set_transient_for (BroadwayServer *server,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
broadway_server_surface_set_modal_hint (BroadwayServer *server,
|
||||
int id, gboolean modal_hint)
|
||||
{
|
||||
BroadwaySurface *surface;
|
||||
|
||||
surface = broadway_server_lookup_surface (server, id);
|
||||
if (surface == NULL)
|
||||
return;
|
||||
|
||||
surface->modal_hint = modal_hint;
|
||||
}
|
||||
|
||||
gboolean
|
||||
broadway_server_has_client (BroadwayServer *server)
|
||||
{
|
||||
|
@@ -130,9 +130,6 @@ gboolean broadway_server_surface_move_resize (BroadwayServer *
|
||||
int height);
|
||||
void broadway_server_focus_surface (BroadwayServer *server,
|
||||
int new_focused_surface);
|
||||
void broadway_server_surface_set_modal_hint (BroadwayServer *server,
|
||||
int id,
|
||||
gboolean modal_hint);
|
||||
|
||||
|
||||
#endif /* __BROADWAY_SERVER__ */
|
||||
|
@@ -380,11 +380,6 @@ client_handle_request (BroadwayClient *client,
|
||||
case BROADWAY_REQUEST_SET_SHOW_KEYBOARD:
|
||||
broadway_server_set_show_keyboard (server, request->set_show_keyboard.show_keyboard);
|
||||
break;
|
||||
case BROADWAY_REQUEST_SET_MODAL_HINT:
|
||||
broadway_server_surface_set_modal_hint (server,
|
||||
request->set_modal_hint.id,
|
||||
request->set_modal_hint.modal_hint);
|
||||
break;
|
||||
default:
|
||||
g_warning ("Unknown request of type %d", request->base.type);
|
||||
}
|
||||
|
@@ -561,18 +561,6 @@ _gdk_broadway_server_surface_set_transient_for (GdkBroadwayServer *server,
|
||||
BROADWAY_REQUEST_SET_TRANSIENT_FOR);
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_broadway_server_surface_set_modal_hint (GdkBroadwayServer *server,
|
||||
int id, gboolean modal_hint)
|
||||
{
|
||||
BroadwayRequestSetModalHint msg;
|
||||
|
||||
msg.id = id;
|
||||
msg.modal_hint = modal_hint;
|
||||
gdk_broadway_server_send_message (server, msg,
|
||||
BROADWAY_REQUEST_SET_MODAL_HINT);
|
||||
}
|
||||
|
||||
static int
|
||||
open_shared_memory (void)
|
||||
{
|
||||
|
@@ -78,8 +78,5 @@ gboolean _gdk_broadway_server_surface_move_resize (GdkBroadwaySe
|
||||
int y,
|
||||
int width,
|
||||
int height);
|
||||
void _gdk_broadway_server_surface_set_modal_hint (GdkBroadwayServer *server,
|
||||
int id,
|
||||
gboolean modal_hint);
|
||||
|
||||
#endif /* __GDK_BROADWAY_SERVER__ */
|
||||
|
@@ -82,27 +82,6 @@ gdk_event_source_check (GSource *source)
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_focus_change (GdkEvent *event)
|
||||
{
|
||||
GdkEvent *focus_event;
|
||||
gboolean focus_in = (gdk_event_get_event_type (event) == GDK_ENTER_NOTIFY);
|
||||
|
||||
if (gdk_crossing_event_get_detail (event) == GDK_NOTIFY_INFERIOR)
|
||||
return;
|
||||
|
||||
if (!gdk_crossing_event_get_focus (event) )
|
||||
return;
|
||||
|
||||
focus_event = gdk_focus_event_new (gdk_event_get_surface (event),
|
||||
gdk_event_get_device (event),
|
||||
focus_in);
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
gdk_display_put_event (gdk_event_get_display (event), focus_event);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
gdk_event_unref (focus_event);
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_broadway_events_got_input (GdkDisplay *display,
|
||||
BroadwayInputMsg *message)
|
||||
@@ -131,8 +110,6 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
|
||||
|
||||
node = _gdk_event_queue_append (display, event);
|
||||
_gdk_windowing_got_event (display, node, event, message->base.serial);
|
||||
|
||||
handle_focus_change (event);
|
||||
}
|
||||
break;
|
||||
case BROADWAY_EVENT_LEAVE:
|
||||
@@ -149,8 +126,6 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
|
||||
message->crossing.mode,
|
||||
GDK_NOTIFY_ANCESTOR);
|
||||
|
||||
handle_focus_change (event);
|
||||
|
||||
node = _gdk_event_queue_append (display, event);
|
||||
_gdk_windowing_got_event (display, node, event, message->base.serial);
|
||||
}
|
||||
|
@@ -709,21 +709,6 @@ gdk_broadway_surface_set_transient_for (GdkSurface *surface,
|
||||
_gdk_broadway_server_surface_set_transient_for (display->server, impl->id, impl->transient_for);
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_broadway_surface_set_modal_hint (GdkSurface *surface,
|
||||
gboolean modal)
|
||||
{
|
||||
GdkBroadwayDisplay *display;
|
||||
GdkBroadwaySurface *impl;
|
||||
|
||||
impl = GDK_BROADWAY_SURFACE (surface);
|
||||
|
||||
impl->modal_hint = modal;
|
||||
|
||||
display = GDK_BROADWAY_DISPLAY (gdk_surface_get_display (surface));
|
||||
_gdk_broadway_server_surface_set_modal_hint (display->server, impl->id, impl->modal_hint);
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_broadway_surface_get_geometry (GdkSurface *surface,
|
||||
int *x,
|
||||
@@ -1448,8 +1433,6 @@ gdk_broadway_toplevel_set_property (GObject *object,
|
||||
break;
|
||||
|
||||
case LAST_PROP + GDK_TOPLEVEL_PROP_MODAL:
|
||||
gdk_broadway_surface_set_modal_hint (surface, g_value_get_boolean (value));
|
||||
g_object_notify_by_pspec (G_OBJECT (surface), pspec);
|
||||
break;
|
||||
|
||||
case LAST_PROP + GDK_TOPLEVEL_PROP_ICON_LIST:
|
||||
@@ -1496,10 +1479,6 @@ gdk_broadway_toplevel_get_property (GObject *object,
|
||||
g_value_set_object (value, surface->transient_for);
|
||||
break;
|
||||
|
||||
case LAST_PROP + GDK_TOPLEVEL_PROP_MODAL:
|
||||
g_value_set_boolean (value, surface->modal_hint);
|
||||
break;
|
||||
|
||||
case LAST_PROP + GDK_TOPLEVEL_PROP_ICON_LIST:
|
||||
g_value_set_pointer (value, NULL);
|
||||
break;
|
||||
|
@@ -54,7 +54,6 @@ struct _GdkBroadwaySurface
|
||||
|
||||
gboolean dirty;
|
||||
gboolean last_synced;
|
||||
gboolean modal_hint;
|
||||
|
||||
GdkGeometry geometry_hints;
|
||||
GdkSurfaceHints geometry_hints_mask;
|
||||
|
@@ -26,7 +26,6 @@
|
||||
#include "gdkcontentformats.h"
|
||||
#include "gdkcontentserializer.h"
|
||||
#include "gdkcontentdeserializer.h"
|
||||
#include "gdkdebugprivate.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
@@ -214,8 +213,6 @@ file_transfer_portal_register_files (const char **files,
|
||||
afd->len = g_strv_length ((char **)files);
|
||||
afd->start = 0;
|
||||
|
||||
GDK_DEBUG (DND, "file transfer portal: registering %d files", afd->len);
|
||||
|
||||
g_variant_builder_init (&options, G_VARIANT_TYPE_VARDICT);
|
||||
g_variant_builder_add (&options, "{sv}", "writable", g_variant_new_boolean (writable));
|
||||
g_variant_builder_add (&options, "{sv}", "autostop", g_variant_new_boolean (TRUE));
|
||||
@@ -351,8 +348,9 @@ portal_ready (GObject *object,
|
||||
static void
|
||||
portal_file_serializer (GdkContentSerializer *serializer)
|
||||
{
|
||||
GPtrArray *files;
|
||||
GFile *file;
|
||||
const GValue *value;
|
||||
GPtrArray *files;
|
||||
|
||||
files = g_ptr_array_new_with_free_func (g_free);
|
||||
|
||||
@@ -360,24 +358,9 @@ portal_file_serializer (GdkContentSerializer *serializer)
|
||||
|
||||
if (G_VALUE_HOLDS (value, G_TYPE_FILE))
|
||||
{
|
||||
GFile *file;
|
||||
|
||||
file = g_value_get_object (gdk_content_serializer_get_value (serializer));
|
||||
|
||||
if (file && g_file_peek_path (file))
|
||||
{
|
||||
GDK_DEBUG (DND, "file transfer portal: Adding %s", g_file_peek_path (file));
|
||||
g_ptr_array_add (files, g_file_get_path (file));
|
||||
}
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
else if (GDK_DEBUG_CHECK (DND))
|
||||
{
|
||||
char *uri = g_file_get_uri (file);
|
||||
gdk_debug_message ("file transfer portal: %s has no path, dropping\n", uri);
|
||||
g_free (uri);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (file)
|
||||
g_ptr_array_add (files, g_file_get_path (file));
|
||||
g_ptr_array_add (files, NULL);
|
||||
}
|
||||
else if (G_VALUE_HOLDS (value, GDK_TYPE_FILE_LIST))
|
||||
@@ -385,21 +368,7 @@ portal_file_serializer (GdkContentSerializer *serializer)
|
||||
GSList *l;
|
||||
|
||||
for (l = g_value_get_boxed (value); l; l = l->next)
|
||||
{
|
||||
GFile *file = l->data;
|
||||
|
||||
if (file && g_file_peek_path (file))
|
||||
{
|
||||
GDK_DEBUG (DND, "file transfer portal: Adding %s", g_file_peek_path (file));
|
||||
g_ptr_array_add (files, g_file_get_path (file));
|
||||
}
|
||||
else
|
||||
{
|
||||
char *uri = g_file_get_uri (file);
|
||||
gdk_debug_message ("file transfer portal: %s has no path, dropping", uri);
|
||||
g_free (uri);
|
||||
}
|
||||
}
|
||||
g_ptr_array_add (files, g_file_get_path (l->data));
|
||||
|
||||
g_ptr_array_add (files, NULL);
|
||||
}
|
||||
@@ -426,15 +395,6 @@ portal_finish (GObject *object,
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
if (GDK_DEBUG_CHECK (DND))
|
||||
{
|
||||
char *s = g_strjoinv (", ", files);
|
||||
gdk_debug_message ("file transfer portal: Receiving files: %s", s);
|
||||
g_free (s);
|
||||
}
|
||||
#endif
|
||||
|
||||
value = gdk_content_deserializer_get_value (deserializer);
|
||||
if (G_VALUE_HOLDS (value, G_TYPE_FILE))
|
||||
{
|
||||
|
@@ -69,7 +69,6 @@
|
||||
#include <gdk/gdksnapshot.h>
|
||||
#include <gdk/gdksurface.h>
|
||||
#include <gdk/gdktexture.h>
|
||||
#include <gdk/gdktexturedownloader.h>
|
||||
#include <gdk/gdktoplevel.h>
|
||||
#include <gdk/gdktoplevellayout.h>
|
||||
#include <gdk/gdktoplevelsize.h>
|
||||
|
@@ -1149,7 +1149,7 @@ _gdk_display_get_next_serial (GdkDisplay *display)
|
||||
* [method@Gtk.Window.set_auto_startup_notification]
|
||||
* is called to disable that feature.
|
||||
*
|
||||
* Deprecated: 4.10: Using [method@Gdk.Toplevel.set_startup_id] is sufficient
|
||||
* Deprecated: 4.10. Using gdk_toplevel_set_startup_id() is sufficient.
|
||||
*/
|
||||
void
|
||||
gdk_display_notify_startup_complete (GdkDisplay *display,
|
||||
@@ -1168,8 +1168,6 @@ gdk_display_notify_startup_complete (GdkDisplay *display,
|
||||
* if no ID has been defined.
|
||||
*
|
||||
* Returns: (nullable): the startup notification ID for @display
|
||||
*
|
||||
* Deprecated: 4.10
|
||||
*/
|
||||
const char *
|
||||
gdk_display_get_startup_notification_id (GdkDisplay *display)
|
||||
|
@@ -86,7 +86,7 @@ GdkClipboard * gdk_display_get_primary_clipboard (GdkDisplay
|
||||
GDK_DEPRECATED_IN_4_10_FOR(gdk_toplevel_set_startup_id)
|
||||
void gdk_display_notify_startup_complete (GdkDisplay *display,
|
||||
const char *startup_id);
|
||||
GDK_DEPRECATED_IN_4_10
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
const char * gdk_display_get_startup_notification_id (GdkDisplay *display);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
|
@@ -1511,6 +1511,7 @@ gdk_button_event_get_button (GdkEvent *event)
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ GdkKeyEvent */
|
||||
|
||||
/**
|
||||
@@ -1971,6 +1972,7 @@ gdk_key_event_get_match (GdkEvent *event,
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ GdkTouchEvent */
|
||||
|
||||
/**
|
||||
@@ -2107,6 +2109,7 @@ gdk_touch_event_get_emulating_pointer (GdkEvent *event)
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ GdkCrossingEvent */
|
||||
|
||||
/**
|
||||
@@ -2250,6 +2253,7 @@ gdk_crossing_event_get_detail (GdkEvent *event)
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ GdkDeleteEvent */
|
||||
|
||||
/**
|
||||
@@ -2280,6 +2284,7 @@ gdk_delete_event_new (GdkSurface *surface)
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ GdkFocusEvent */
|
||||
|
||||
/**
|
||||
@@ -2336,6 +2341,7 @@ gdk_focus_event_get_in (GdkEvent *event)
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ GdkScrollEvent */
|
||||
|
||||
/**
|
||||
@@ -2594,6 +2600,7 @@ gdk_scroll_event_get_unit (GdkEvent *event)
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ GdkTouchpadEvent */
|
||||
|
||||
/**
|
||||
@@ -2852,6 +2859,7 @@ gdk_touchpad_event_get_pinch_scale (GdkEvent *event)
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ GdkPadEvent */
|
||||
|
||||
/**
|
||||
@@ -3025,6 +3033,7 @@ gdk_pad_event_get_group_mode (GdkEvent *event,
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ GdkMotionEvent */
|
||||
|
||||
/**
|
||||
@@ -3186,6 +3195,7 @@ gdk_event_get_history (GdkEvent *event,
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ GdkProximityEvent */
|
||||
|
||||
/**
|
||||
@@ -3248,6 +3258,7 @@ gdk_proximity_event_new (GdkEventType type,
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ GdkDNDEvent */
|
||||
|
||||
/**
|
||||
@@ -3353,6 +3364,7 @@ gdk_dnd_event_get_drop (GdkEvent *event)
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ GdkGrabBrokenEvent */
|
||||
|
||||
/**
|
||||
@@ -3430,5 +3442,3 @@ gdk_grab_broken_event_get_implicit (GdkEvent *event)
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* vim:set foldmethod=marker expandtab: */
|
||||
|
@@ -584,8 +584,6 @@ gdk_frame_clock_paint_idle (void *data)
|
||||
{
|
||||
priv->requested &= ~GDK_FRAME_CLOCK_PHASE_LAYOUT;
|
||||
_gdk_frame_clock_emit_layout (clock);
|
||||
if (priv->requested & GDK_FRAME_CLOCK_PHASE_LAYOUT)
|
||||
g_print ("looping in layout %d\n", iter);
|
||||
}
|
||||
if (iter == 5)
|
||||
g_warning ("gdk-frame-clock: layout continuously requested, giving up after 4 tries");
|
||||
@@ -811,12 +809,3 @@ _gdk_frame_clock_idle_new (void)
|
||||
|
||||
return GDK_FRAME_CLOCK (clock);
|
||||
}
|
||||
|
||||
GdkFrameClockPhase
|
||||
gdk_frame_clock_get_current_phase (GdkFrameClock *clock)
|
||||
{
|
||||
GdkFrameClockIdle *clock_idle = GDK_FRAME_CLOCK_IDLE (clock);
|
||||
GdkFrameClockIdlePrivate *priv = clock_idle->priv;
|
||||
|
||||
return priv->phase;
|
||||
}
|
||||
|
@@ -127,8 +127,6 @@ void _gdk_frame_clock_emit_paint (GdkFrameClock *frame_clock);
|
||||
void _gdk_frame_clock_emit_after_paint (GdkFrameClock *frame_clock);
|
||||
void _gdk_frame_clock_emit_resume_events (GdkFrameClock *frame_clock);
|
||||
|
||||
GdkFrameClockPhase gdk_frame_clock_get_current_phase (GdkFrameClock *frame_clock);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GDK_FRAME_CLOCK_PRIVATE_H__ */
|
||||
|
@@ -501,18 +501,6 @@ gdk_gl_context_real_is_shared (GdkGLContext *self,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gdk_gl_context_real_is_current (GdkGLContext *self)
|
||||
{
|
||||
#ifdef HAVE_EGL
|
||||
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
|
||||
|
||||
return priv->egl_context == eglGetCurrentContext ();
|
||||
#else
|
||||
return TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gdk_gl_context_real_clear_current (GdkGLContext *context)
|
||||
{
|
||||
@@ -682,7 +670,6 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
|
||||
klass->is_shared = gdk_gl_context_real_is_shared;
|
||||
klass->make_current = gdk_gl_context_real_make_current;
|
||||
klass->clear_current = gdk_gl_context_real_clear_current;
|
||||
klass->is_current = gdk_gl_context_real_is_current;
|
||||
klass->get_default_framebuffer = gdk_gl_context_real_get_default_framebuffer;
|
||||
|
||||
draw_context_class->begin_frame = gdk_gl_context_real_begin_frame;
|
||||
@@ -1564,12 +1551,6 @@ gdk_gl_context_check_extensions (GdkGLContext *context)
|
||||
priv->extensions_checked = TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gdk_gl_context_check_is_current (GdkGLContext *context)
|
||||
{
|
||||
return GDK_GL_CONTEXT_GET_CLASS (context)->is_current (context);
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_gl_context_make_current:
|
||||
* @context: a `GdkGLContext`
|
||||
@@ -1588,7 +1569,7 @@ gdk_gl_context_make_current (GdkGLContext *context)
|
||||
masked_context = mask_context (context, surfaceless);
|
||||
|
||||
current = g_private_get (&thread_current_context);
|
||||
if (current == masked_context && gdk_gl_context_check_is_current (context))
|
||||
if (current == masked_context)
|
||||
return;
|
||||
|
||||
/* we need to realize the GdkGLContext if it wasn't explicitly realized */
|
||||
@@ -1759,18 +1740,10 @@ GdkGLContext *
|
||||
gdk_gl_context_get_current (void)
|
||||
{
|
||||
MaskedContext *current;
|
||||
GdkGLContext *context;
|
||||
|
||||
current = g_private_get (&thread_current_context);
|
||||
context = unmask_context (current);
|
||||
|
||||
if (context && !gdk_gl_context_check_is_current (context))
|
||||
{
|
||||
g_private_replace (&thread_current_context, NULL);
|
||||
context = NULL;
|
||||
}
|
||||
|
||||
return context;
|
||||
return unmask_context (current);
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@@ -83,7 +83,6 @@ struct _GdkGLContextClass
|
||||
gboolean (* make_current) (GdkGLContext *context,
|
||||
gboolean surfaceless);
|
||||
gboolean (* clear_current) (GdkGLContext *context);
|
||||
gboolean (* is_current) (GdkGLContext *context);
|
||||
cairo_region_t * (* get_damage) (GdkGLContext *context);
|
||||
|
||||
gboolean (* is_shared) (GdkGLContext *self,
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include "gdkglcontextprivate.h"
|
||||
#include "gdkmemoryformatprivate.h"
|
||||
#include "gdkmemorytextureprivate.h"
|
||||
#include "gdktextureprivate.h"
|
||||
|
||||
#include <epoxy/gl.h>
|
||||
|
||||
@@ -52,8 +53,10 @@ struct _GdkGLTextureClass {
|
||||
G_DEFINE_TYPE (GdkGLTexture, gdk_gl_texture, GDK_TYPE_TEXTURE)
|
||||
|
||||
static void
|
||||
drop_gl_resources (GdkGLTexture *self)
|
||||
gdk_gl_texture_dispose (GObject *object)
|
||||
{
|
||||
GdkGLTexture *self = GDK_GL_TEXTURE (object);
|
||||
|
||||
if (self->destroy)
|
||||
{
|
||||
self->destroy (self->data);
|
||||
@@ -63,29 +66,17 @@ drop_gl_resources (GdkGLTexture *self)
|
||||
|
||||
g_clear_object (&self->context);
|
||||
self->id = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_gl_texture_dispose (GObject *object)
|
||||
{
|
||||
GdkGLTexture *self = GDK_GL_TEXTURE (object);
|
||||
|
||||
drop_gl_resources (self);
|
||||
|
||||
g_clear_object (&self->saved);
|
||||
|
||||
G_OBJECT_CLASS (gdk_gl_texture_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
typedef void (* GLFunc) (GdkGLTexture *self,
|
||||
GdkGLContext *context,
|
||||
gpointer data);
|
||||
|
||||
typedef struct _InvokeData
|
||||
{
|
||||
GdkGLTexture *self;
|
||||
volatile int spinlock;
|
||||
GLFunc func;
|
||||
GFunc func;
|
||||
gpointer data;
|
||||
} InvokeData;
|
||||
|
||||
@@ -100,7 +91,7 @@ gdk_gl_texture_invoke_callback (gpointer data)
|
||||
gdk_gl_context_make_current (context);
|
||||
glBindTexture (GL_TEXTURE_2D, invoke->self->id);
|
||||
|
||||
invoke->func (invoke->self, context, invoke->data);
|
||||
invoke->func (invoke->self, invoke->data);
|
||||
|
||||
g_atomic_int_set (&invoke->spinlock, 1);
|
||||
|
||||
@@ -109,7 +100,7 @@ gdk_gl_texture_invoke_callback (gpointer data)
|
||||
|
||||
static void
|
||||
gdk_gl_texture_run (GdkGLTexture *self,
|
||||
GLFunc func,
|
||||
GFunc func,
|
||||
gpointer data)
|
||||
{
|
||||
InvokeData invoke = { self, 0, func, data };
|
||||
@@ -154,19 +145,19 @@ gdk_gl_texture_find_format (gboolean use_es,
|
||||
}
|
||||
|
||||
static inline void
|
||||
gdk_gl_texture_do_download (GdkGLTexture *self,
|
||||
GdkGLContext *context,
|
||||
gpointer download_)
|
||||
gdk_gl_texture_do_download (gpointer texture_,
|
||||
gpointer download_)
|
||||
{
|
||||
GdkTexture *texture = GDK_TEXTURE (self);
|
||||
gsize expected_stride;
|
||||
GdkGLTexture *self = texture_;
|
||||
GdkTexture *texture = texture_;
|
||||
Download *download = download_;
|
||||
GLenum gl_internal_format, gl_format, gl_type;
|
||||
|
||||
expected_stride = texture->width * gdk_memory_format_bytes_per_pixel (download->format);
|
||||
|
||||
if (download->stride == expected_stride &&
|
||||
!gdk_gl_context_get_use_es (context) &&
|
||||
!gdk_gl_context_get_use_es (self->context) &&
|
||||
gdk_memory_format_gl_format (download->format, TRUE, &gl_internal_format, &gl_format, &gl_type))
|
||||
{
|
||||
glGetTexImage (GL_TEXTURE_2D,
|
||||
@@ -184,11 +175,11 @@ gdk_gl_texture_do_download (GdkGLTexture *self,
|
||||
glGenFramebuffers (1, &fbo);
|
||||
glBindFramebuffer (GL_FRAMEBUFFER, fbo);
|
||||
glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, self->id, 0);
|
||||
if (gdk_gl_context_check_version (context, 4, 3, 3, 1))
|
||||
if (gdk_gl_context_check_version (self->context, 4, 3, 3, 1))
|
||||
{
|
||||
glGetFramebufferParameteriv (GL_FRAMEBUFFER, GL_IMPLEMENTATION_COLOR_READ_FORMAT, &gl_read_format);
|
||||
glGetFramebufferParameteriv (GL_FRAMEBUFFER, GL_IMPLEMENTATION_COLOR_READ_TYPE, &gl_read_type);
|
||||
if (!gdk_gl_texture_find_format (gdk_gl_context_get_use_es (context), gl_read_format, gl_read_type, &actual_format))
|
||||
if (!gdk_gl_texture_find_format (gdk_gl_context_get_use_es (self->context), gl_read_format, gl_read_type, &actual_format))
|
||||
actual_format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED; /* pray */
|
||||
}
|
||||
else
|
||||
@@ -202,7 +193,7 @@ gdk_gl_texture_do_download (GdkGLTexture *self,
|
||||
(download->stride == expected_stride))
|
||||
{
|
||||
glReadPixels (0, 0,
|
||||
texture->width, texture->height,
|
||||
texture->width, texture->height,
|
||||
gl_read_format,
|
||||
gl_read_type,
|
||||
download->data);
|
||||
@@ -213,7 +204,7 @@ gdk_gl_texture_do_download (GdkGLTexture *self,
|
||||
guchar *pixels = g_malloc_n (texture->width * actual_bpp, texture->height);
|
||||
|
||||
glReadPixels (0, 0,
|
||||
texture->width, texture->height,
|
||||
texture->width, texture->height,
|
||||
gl_read_format,
|
||||
gl_read_type,
|
||||
pixels);
|
||||
@@ -306,7 +297,15 @@ gdk_gl_texture_release (GdkGLTexture *self)
|
||||
self->saved = GDK_TEXTURE (gdk_memory_texture_from_texture (texture,
|
||||
gdk_texture_get_format (texture)));
|
||||
|
||||
drop_gl_resources (self);
|
||||
if (self->destroy)
|
||||
{
|
||||
self->destroy (self->data);
|
||||
self->destroy = NULL;
|
||||
self->data = NULL;
|
||||
}
|
||||
|
||||
g_clear_object (&self->context);
|
||||
self->id = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -222,7 +222,7 @@ gdk_memory_texture_from_texture (GdkTexture *texture,
|
||||
data = g_malloc_n (stride, texture->height);
|
||||
|
||||
gdk_texture_do_download (texture, format, data, stride);
|
||||
bytes = g_bytes_new_take (data, stride * texture->height);
|
||||
bytes = g_bytes_new_take (data, stride);
|
||||
result = gdk_memory_texture_new (texture->width,
|
||||
texture->height,
|
||||
format,
|
||||
@@ -233,11 +233,15 @@ gdk_memory_texture_from_texture (GdkTexture *texture,
|
||||
return GDK_MEMORY_TEXTURE (result);
|
||||
}
|
||||
|
||||
GBytes *
|
||||
gdk_memory_texture_get_bytes (GdkMemoryTexture *self,
|
||||
gsize *out_stride)
|
||||
const guchar *
|
||||
gdk_memory_texture_get_data (GdkMemoryTexture *self)
|
||||
{
|
||||
*out_stride = self->stride;
|
||||
return self->bytes;
|
||||
return g_bytes_get_data (self->bytes, NULL);
|
||||
}
|
||||
|
||||
gsize
|
||||
gdk_memory_texture_get_stride (GdkMemoryTexture *self)
|
||||
{
|
||||
return self->stride;
|
||||
}
|
||||
|
||||
|
@@ -37,8 +37,8 @@ GdkTexture * gdk_memory_texture_new_subtexture (GdkMemoryTexture *
|
||||
int width,
|
||||
int height);
|
||||
|
||||
GBytes * gdk_memory_texture_get_bytes (GdkMemoryTexture *self,
|
||||
gsize *out_stride);
|
||||
const guchar * gdk_memory_texture_get_data (GdkMemoryTexture *self);
|
||||
gsize gdk_memory_texture_get_stride (GdkMemoryTexture *self);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
@@ -39,7 +39,6 @@
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_DESCRIPTION,
|
||||
PROP_DISPLAY,
|
||||
PROP_MANUFACTURER,
|
||||
PROP_MODEL,
|
||||
@@ -82,10 +81,6 @@ gdk_monitor_get_property (GObject *object,
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_DESCRIPTION:
|
||||
g_value_set_string (value, monitor->description);
|
||||
break;
|
||||
|
||||
case PROP_DISPLAY:
|
||||
g_value_set_object (value, monitor->display);
|
||||
break;
|
||||
@@ -159,7 +154,6 @@ gdk_monitor_finalize (GObject *object)
|
||||
{
|
||||
GdkMonitor *monitor = GDK_MONITOR (object);
|
||||
|
||||
g_free (monitor->description);
|
||||
g_free (monitor->connector);
|
||||
g_free (monitor->manufacturer);
|
||||
g_free (monitor->model);
|
||||
@@ -176,18 +170,6 @@ gdk_monitor_class_init (GdkMonitorClass *class)
|
||||
object_class->get_property = gdk_monitor_get_property;
|
||||
object_class->set_property = gdk_monitor_set_property;
|
||||
|
||||
/**
|
||||
* GdkMonitor:description: (attributes org.gtk.Property.get=gdk_monitor_get_description)
|
||||
*
|
||||
* A short description of the monitor, meant for display to the user.
|
||||
*
|
||||
* Since: 4.10
|
||||
*/
|
||||
props[PROP_DESCRIPTION] =
|
||||
g_param_spec_string ("description", NULL, NULL,
|
||||
NULL,
|
||||
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
/**
|
||||
* GdkMonitor:display: (attributes org.gtk.Property.get=gdk_monitor_get_display)
|
||||
*
|
||||
@@ -395,10 +377,6 @@ gdk_monitor_get_height_mm (GdkMonitor *monitor)
|
||||
*
|
||||
* Gets the name of the monitor's connector, if available.
|
||||
*
|
||||
* These are strings such as "eDP-1", or "HDMI-2". They depend
|
||||
* on software and hardware configuration, and should not be
|
||||
* relied on as stable identifiers of a specific monitor.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): the name of the connector
|
||||
*/
|
||||
const char *
|
||||
@@ -641,33 +619,3 @@ gdk_monitor_is_valid (GdkMonitor *monitor)
|
||||
|
||||
return monitor->valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_monitor_get_description: (attributes org.gtk.Method.get_property=description)
|
||||
* @monitor: a `GdkMonitor`
|
||||
*
|
||||
* Gets a string describing the monitor, if available.
|
||||
*
|
||||
* This can be used to identify a monitor in the UI.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): the monitor description
|
||||
*
|
||||
* Since: 4.10
|
||||
*/
|
||||
const char *
|
||||
gdk_monitor_get_description (GdkMonitor *monitor)
|
||||
{
|
||||
g_return_val_if_fail (GDK_IS_MONITOR (monitor), NULL);
|
||||
|
||||
return monitor->description;
|
||||
}
|
||||
|
||||
void
|
||||
gdk_monitor_set_description (GdkMonitor *monitor,
|
||||
const char *description)
|
||||
{
|
||||
g_free (monitor->description);
|
||||
monitor->description = g_strdup (description);
|
||||
g_object_notify_by_pspec (G_OBJECT (monitor), props[PROP_DESCRIPTION]);
|
||||
}
|
||||
|
||||
|
@@ -86,8 +86,6 @@ GDK_AVAILABLE_IN_ALL
|
||||
GdkSubpixelLayout gdk_monitor_get_subpixel_layout (GdkMonitor *monitor);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gdk_monitor_is_valid (GdkMonitor *monitor);
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
const char * gdk_monitor_get_description (GdkMonitor *monitor);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkMonitor, g_object_unref)
|
||||
|
||||
|
@@ -37,7 +37,6 @@ struct _GdkMonitor {
|
||||
char *manufacturer;
|
||||
char *model;
|
||||
char *connector;
|
||||
char *description;
|
||||
GdkRectangle geometry;
|
||||
int width_mm;
|
||||
int height_mm;
|
||||
@@ -71,8 +70,6 @@ void gdk_monitor_set_refresh_rate (GdkMonitor *monitor,
|
||||
void gdk_monitor_set_subpixel_layout (GdkMonitor *monitor,
|
||||
GdkSubpixelLayout subpixel);
|
||||
void gdk_monitor_invalidate (GdkMonitor *monitor);
|
||||
void gdk_monitor_set_description (GdkMonitor *monitor,
|
||||
const char *description);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#include "gdkmemoryformatprivate.h"
|
||||
#include "gdkmemorytextureprivate.h"
|
||||
#include "gdksurface.h"
|
||||
#include "gdktexturedownloaderprivate.h"
|
||||
#include "gdktextureprivate.h"
|
||||
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
||||
@@ -218,9 +218,9 @@ gdk_pixbuf_get_from_surface (cairo_surface_t *surface,
|
||||
|
||||
static void
|
||||
pixbuf_texture_unref_cb (guchar *pixels,
|
||||
gpointer bytes)
|
||||
gpointer texture)
|
||||
{
|
||||
g_bytes_unref (bytes);
|
||||
g_object_unref (texture);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,27 +238,22 @@ pixbuf_texture_unref_cb (guchar *pixels,
|
||||
GdkPixbuf *
|
||||
gdk_pixbuf_get_from_texture (GdkTexture *texture)
|
||||
{
|
||||
GdkTextureDownloader downloader;
|
||||
GBytes *bytes;
|
||||
gsize stride;
|
||||
GdkMemoryTexture *memtex;
|
||||
gboolean alpha;
|
||||
|
||||
alpha = gdk_memory_format_alpha (gdk_texture_get_format (texture)) != GDK_MEMORY_ALPHA_OPAQUE;
|
||||
|
||||
gdk_texture_downloader_init (&downloader, texture);
|
||||
gdk_texture_downloader_set_format (&downloader,
|
||||
alpha ? GDK_MEMORY_GDK_PIXBUF_ALPHA
|
||||
: GDK_MEMORY_GDK_PIXBUF_OPAQUE);
|
||||
bytes = gdk_texture_downloader_download_bytes (&downloader, &stride);
|
||||
gdk_texture_downloader_finish (&downloader);
|
||||
memtex = gdk_memory_texture_from_texture (texture,
|
||||
alpha ? GDK_MEMORY_GDK_PIXBUF_ALPHA
|
||||
: GDK_MEMORY_GDK_PIXBUF_OPAQUE);
|
||||
|
||||
return gdk_pixbuf_new_from_data (g_bytes_get_data (bytes, NULL),
|
||||
return gdk_pixbuf_new_from_data (gdk_memory_texture_get_data (memtex),
|
||||
GDK_COLORSPACE_RGB,
|
||||
alpha,
|
||||
8,
|
||||
gdk_texture_get_width (texture),
|
||||
gdk_texture_get_height (texture),
|
||||
stride,
|
||||
gdk_texture_get_width (GDK_TEXTURE (memtex)),
|
||||
gdk_texture_get_height (GDK_TEXTURE (memtex)),
|
||||
gdk_memory_texture_get_stride (memtex),
|
||||
pixbuf_texture_unref_cb,
|
||||
bytes);
|
||||
memtex);
|
||||
}
|
||||
|
@@ -722,9 +722,6 @@ gdk_texture_download_surface (GdkTexture *texture)
|
||||
* cairo_image_surface_get_stride (surface));
|
||||
* cairo_surface_mark_dirty (surface);
|
||||
* ```
|
||||
*
|
||||
* For more flexible download capabilites, see
|
||||
* [struct@Gdk.TextureDownloader].
|
||||
*/
|
||||
void
|
||||
gdk_texture_download (GdkTexture *texture,
|
||||
@@ -741,29 +738,9 @@ gdk_texture_download (GdkTexture *texture,
|
||||
stride);
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_texture_get_format:
|
||||
* @self: a GdkTexture
|
||||
*
|
||||
* Gets the memory format most closely associated with the data of
|
||||
* the texture.
|
||||
*
|
||||
* Note that it may not be an exact match for texture data
|
||||
* stored on the GPU or with compression.
|
||||
*
|
||||
* The format can give an indication about the bit depth and opacity
|
||||
* of the texture and is useful to determine the best format for
|
||||
* downloading the texture.
|
||||
*
|
||||
* Returns: the preferred format for the texture's data
|
||||
*
|
||||
* Since: 4.10
|
||||
**/
|
||||
GdkMemoryFormat
|
||||
gdk_texture_get_format (GdkTexture *self)
|
||||
{
|
||||
g_return_val_if_fail (GDK_IS_TEXTURE (self), GDK_MEMORY_DEFAULT);
|
||||
|
||||
return self->format;
|
||||
}
|
||||
|
||||
|
@@ -24,7 +24,6 @@
|
||||
#endif
|
||||
|
||||
#include <gdk/gdkversionmacros.h>
|
||||
#include <gdk/gdkenums.h>
|
||||
#include <gdk/gdktypes.h>
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
||||
@@ -83,8 +82,6 @@ GDK_AVAILABLE_IN_ALL
|
||||
int gdk_texture_get_width (GdkTexture *texture) G_GNUC_PURE;
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
int gdk_texture_get_height (GdkTexture *texture) G_GNUC_PURE;
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
GdkMemoryFormat gdk_texture_get_format (GdkTexture *self) G_GNUC_PURE;
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gdk_texture_download (GdkTexture *texture,
|
||||
|
@@ -1,268 +0,0 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2023 Benjamin Otte
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* GdkTextureDownloader:
|
||||
*
|
||||
* The `GdkTextureDownloader` is used to download the contents of a
|
||||
* [class@Gdk.Texture].
|
||||
*
|
||||
* It is intended to be created as a short-term object for a single download,
|
||||
* but can be used for multipe downloads of different textures or with different
|
||||
* settings.
|
||||
*
|
||||
* `GdkTextureDownloader` can be used to convert data between different formats.
|
||||
* Create a `GdkTexture` for the existing format and then download it in a
|
||||
* different format.
|
||||
*
|
||||
* Since: 4.10
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gdktexturedownloaderprivate.h"
|
||||
|
||||
#include "gdkmemoryformatprivate.h"
|
||||
#include "gdkmemorytextureprivate.h"
|
||||
#include "gdktextureprivate.h"
|
||||
|
||||
G_DEFINE_BOXED_TYPE (GdkTextureDownloader, gdk_texture_downloader,
|
||||
gdk_texture_downloader_copy,
|
||||
gdk_texture_downloader_free)
|
||||
|
||||
|
||||
void
|
||||
gdk_texture_downloader_init (GdkTextureDownloader *self,
|
||||
GdkTexture *texture)
|
||||
{
|
||||
self->texture = g_object_ref (texture);
|
||||
self->format = GDK_MEMORY_DEFAULT;
|
||||
}
|
||||
|
||||
void
|
||||
gdk_texture_downloader_finish (GdkTextureDownloader *self)
|
||||
{
|
||||
g_object_unref (self->texture);
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_texture_downloader_new:
|
||||
* @texture: texture to download
|
||||
*
|
||||
* Creates a new texture downloader for @texture.
|
||||
*
|
||||
* Returns: A new texture downloader
|
||||
*
|
||||
* Since: 4.10
|
||||
**/
|
||||
GdkTextureDownloader *
|
||||
gdk_texture_downloader_new (GdkTexture *texture)
|
||||
{
|
||||
GdkTextureDownloader *self;
|
||||
|
||||
g_return_val_if_fail (GDK_IS_TEXTURE (texture), NULL);
|
||||
|
||||
self = g_slice_new (GdkTextureDownloader);
|
||||
gdk_texture_downloader_init (self, texture);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_texture_downloader_copy:
|
||||
* @self: the downloader to copy
|
||||
*
|
||||
* Creates a copy of the downloader.
|
||||
*
|
||||
* This function is meant for language bindings.
|
||||
*
|
||||
* Returns: A copy of the downloader
|
||||
*
|
||||
* Since: 4.10
|
||||
**/
|
||||
GdkTextureDownloader *
|
||||
gdk_texture_downloader_copy (const GdkTextureDownloader *self)
|
||||
{
|
||||
GdkTextureDownloader *copy;
|
||||
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
|
||||
copy = gdk_texture_downloader_new (self->texture);
|
||||
gdk_texture_downloader_set_format (copy, self->format);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_texture_downloader_free:
|
||||
* @self: texture downloader to free
|
||||
*
|
||||
* Frees the given downloader and all its associated resources.
|
||||
*
|
||||
* Since: 4.10
|
||||
**/
|
||||
void
|
||||
gdk_texture_downloader_free (GdkTextureDownloader *self)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
gdk_texture_downloader_finish (self);
|
||||
g_slice_free (GdkTextureDownloader, self);
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_texture_downloader_set_texture:
|
||||
* @self: a texture downloader
|
||||
* @texture: the new texture to download
|
||||
*
|
||||
* Changes the texture the downloader will download.
|
||||
*
|
||||
* Since: 4.10
|
||||
**/
|
||||
void
|
||||
gdk_texture_downloader_set_texture (GdkTextureDownloader *self,
|
||||
GdkTexture *texture)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (GDK_IS_TEXTURE (texture));
|
||||
|
||||
g_set_object (&self->texture, texture);
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_texture_downloader_get_texture:
|
||||
* @self: a texture downloader
|
||||
*
|
||||
* Gets the texture that the downloader will download.
|
||||
*
|
||||
* Returns: (transfer none): The texture to download
|
||||
*
|
||||
* Since: 4.10
|
||||
**/
|
||||
GdkTexture *
|
||||
gdk_texture_downloader_get_texture (const GdkTextureDownloader *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
|
||||
return self->texture;
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_texture_downloader_set_format:
|
||||
* @self: a texture downloader
|
||||
* @format: the format to use
|
||||
*
|
||||
* Sets the format the downloader will download.
|
||||
*
|
||||
* By default, GDK_MEMORY_DEFAULT is set.
|
||||
*
|
||||
* Since: 4.10
|
||||
*/
|
||||
void
|
||||
gdk_texture_downloader_set_format (GdkTextureDownloader *self,
|
||||
GdkMemoryFormat format)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
self->format = format;
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_texture_downloader_get_format:
|
||||
* @self: a texture downloader
|
||||
*
|
||||
* Gets the format that the data will be downloaded in.
|
||||
*
|
||||
* Returns: The format of the download
|
||||
*
|
||||
* Since: 4.10
|
||||
**/
|
||||
GdkMemoryFormat
|
||||
gdk_texture_downloader_get_format (const GdkTextureDownloader *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, GDK_MEMORY_DEFAULT);
|
||||
|
||||
return self->format;
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_texture_downloader_download_into:
|
||||
* @self: a texture downloader
|
||||
* @data: (array): pointer to enough memory to be filled with the
|
||||
* downloaded data of the texture
|
||||
* @stride: rowstride in bytes
|
||||
*
|
||||
* Downloads the @texture into local memory.
|
||||
*
|
||||
* Since: 4.10
|
||||
**/
|
||||
void
|
||||
gdk_texture_downloader_download_into (const GdkTextureDownloader *self,
|
||||
guchar *data,
|
||||
gsize stride)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (data != NULL);
|
||||
g_return_if_fail (stride >= gdk_texture_get_width (self->texture) * gdk_memory_format_bytes_per_pixel (self->format));
|
||||
|
||||
gdk_texture_do_download (self->texture, self->format, data, stride);
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_texture_downloader_download_bytes:
|
||||
* @self: the downloader
|
||||
* @out_stride: (out): The stride of the resulting data in bytes.
|
||||
*
|
||||
* Downloads the given texture pixels into a `GBytes`. The rowstride will
|
||||
* be stored in the stride value.
|
||||
*
|
||||
* This function will abort if it tries to download a large texture and
|
||||
* fails to allocate memory. If you think that may happen, you should
|
||||
* handle memory allocation yourself and use
|
||||
* gdk_texture_downloader_download_into() once allocation succeeded.
|
||||
*
|
||||
* Returns: The downloaded pixels.
|
||||
*
|
||||
* Since: 4.10
|
||||
**/
|
||||
GBytes *
|
||||
gdk_texture_downloader_download_bytes (const GdkTextureDownloader *self,
|
||||
gsize *out_stride)
|
||||
{
|
||||
guchar *data;
|
||||
gsize stride;
|
||||
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
g_return_val_if_fail (out_stride != NULL, NULL);
|
||||
|
||||
if (GDK_IS_MEMORY_TEXTURE (self->texture) &&
|
||||
gdk_texture_get_format (self->texture) == self->format)
|
||||
{
|
||||
GdkMemoryTexture *memtex = GDK_MEMORY_TEXTURE (self->texture);
|
||||
|
||||
return g_bytes_ref (gdk_memory_texture_get_bytes (memtex, out_stride));
|
||||
}
|
||||
|
||||
stride = self->texture->width * gdk_memory_format_bytes_per_pixel (self->format);
|
||||
data = g_malloc_n (stride, self->texture->height);
|
||||
|
||||
gdk_texture_do_download (self->texture, self->format, data, stride);
|
||||
|
||||
*out_stride = stride;
|
||||
return g_bytes_new_take (data, stride * self->texture->height);
|
||||
}
|
||||
|
@@ -1,69 +0,0 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2023 Benjamin Otte
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_TEXTURE_DOWNLOADER_H__
|
||||
#define __GTK_TEXTURE_DOWNLOADER_H__
|
||||
|
||||
#if !defined (__GDK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gdk/gdk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
|
||||
#include <gdk/gdkversionmacros.h>
|
||||
#include <gdk/gdkenums.h>
|
||||
#include <gdk/gdktypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GDK_TYPE_TEXTURE_DOWNLOADER (gdk_texture_downloader_get_type ())
|
||||
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
GType gdk_texture_downloader_get_type (void) G_GNUC_CONST;
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
GdkTextureDownloader * gdk_texture_downloader_new (GdkTexture *texture);
|
||||
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
GdkTextureDownloader * gdk_texture_downloader_copy (const GdkTextureDownloader *self);
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
void gdk_texture_downloader_free (GdkTextureDownloader *self);
|
||||
|
||||
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
void gdk_texture_downloader_set_texture (GdkTextureDownloader *self,
|
||||
GdkTexture *texture);
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
GdkTexture * gdk_texture_downloader_get_texture (const GdkTextureDownloader *self);
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
void gdk_texture_downloader_set_format (GdkTextureDownloader *self,
|
||||
GdkMemoryFormat format);
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
GdkMemoryFormat gdk_texture_downloader_get_format (const GdkTextureDownloader *self);
|
||||
|
||||
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
void gdk_texture_downloader_download_into (const GdkTextureDownloader *self,
|
||||
guchar *data,
|
||||
gsize stride);
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
GBytes * gdk_texture_downloader_download_bytes (const GdkTextureDownloader *self,
|
||||
gsize *out_stride);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkTextureDownloader, gdk_texture_downloader_free)
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_TEXTURE_DOWNLOADER_H__ */
|
@@ -1,41 +0,0 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
*
|
||||
* Copyright (C) 2023 Benjamin Otte
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GTK_TEXTURE_DOWNLOADER_PRIVATE_H__
|
||||
#define __GTK_TEXTURE_DOWNLOADER_PRIVATE_H__
|
||||
|
||||
#include "gdktexturedownloader.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
struct _GdkTextureDownloader
|
||||
{
|
||||
/*< private >*/
|
||||
GdkTexture *texture;
|
||||
GdkMemoryFormat format;
|
||||
};
|
||||
|
||||
void gdk_texture_downloader_init (GdkTextureDownloader *self,
|
||||
GdkTexture *texture);
|
||||
void gdk_texture_downloader_finish (GdkTextureDownloader *self);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_TEXTURE_DOWNLOADER_PRIVATE_H__ */
|
@@ -43,6 +43,7 @@ void gdk_texture_do_download (GdkTexture
|
||||
GdkMemoryFormat format,
|
||||
guchar *data,
|
||||
gsize stride);
|
||||
GdkMemoryFormat gdk_texture_get_format (GdkTexture *self);
|
||||
gboolean gdk_texture_set_render_data (GdkTexture *self,
|
||||
gpointer key,
|
||||
gpointer data,
|
||||
|
@@ -77,7 +77,6 @@ typedef struct _GdkContentFormats GdkContentFormats;
|
||||
typedef struct _GdkContentProvider GdkContentProvider;
|
||||
typedef struct _GdkCursor GdkCursor;
|
||||
typedef struct _GdkTexture GdkTexture;
|
||||
typedef struct _GdkTextureDownloader GdkTextureDownloader;
|
||||
typedef struct _GdkDevice GdkDevice;
|
||||
typedef struct _GdkDrag GdkDrag;
|
||||
typedef struct _GdkDrop GdkDrop;
|
||||
|
@@ -23,7 +23,7 @@
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include "gdktexture.h"
|
||||
#include "gdktexturedownloaderprivate.h"
|
||||
#include "gdkmemorytextureprivate.h"
|
||||
|
||||
#include "gdkprofilerprivate.h"
|
||||
|
||||
@@ -251,8 +251,7 @@ gdk_save_jpeg (GdkTexture *texture)
|
||||
guchar *data = NULL;
|
||||
gulong size = 0;
|
||||
guchar *input = NULL;
|
||||
GdkTextureDownloader downloader;
|
||||
GBytes *texbytes;
|
||||
GdkMemoryTexture *memtex = NULL;
|
||||
const guchar *texdata;
|
||||
gsize texstride;
|
||||
guchar *row;
|
||||
@@ -271,7 +270,7 @@ gdk_save_jpeg (GdkTexture *texture)
|
||||
free (data);
|
||||
g_free (input);
|
||||
jpeg_destroy_compress (&info);
|
||||
g_clear_pointer (&texbytes, g_bytes_unref);
|
||||
g_clear_object (&memtex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -290,11 +289,10 @@ gdk_save_jpeg (GdkTexture *texture)
|
||||
|
||||
jpeg_mem_dest (&info, &data, &size);
|
||||
|
||||
gdk_texture_downloader_init (&downloader, texture);
|
||||
gdk_texture_downloader_set_format (&downloader, GDK_MEMORY_R8G8B8);
|
||||
texbytes = gdk_texture_downloader_download_bytes (&downloader, &texstride);
|
||||
gdk_texture_downloader_finish (&downloader);
|
||||
texdata = g_bytes_get_data (texbytes, NULL);
|
||||
memtex = gdk_memory_texture_from_texture (texture,
|
||||
GDK_MEMORY_R8G8B8);
|
||||
texdata = gdk_memory_texture_get_data (memtex);
|
||||
texstride = gdk_memory_texture_get_stride (memtex);
|
||||
|
||||
jpeg_start_compress (&info, TRUE);
|
||||
|
||||
@@ -306,7 +304,7 @@ gdk_save_jpeg (GdkTexture *texture)
|
||||
|
||||
jpeg_finish_compress (&info);
|
||||
|
||||
g_bytes_unref (texbytes);
|
||||
g_object_unref (memtex);
|
||||
g_free (input);
|
||||
jpeg_destroy_compress (&info);
|
||||
|
||||
|
@@ -21,9 +21,10 @@
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include "gdkmemoryformatprivate.h"
|
||||
#include "gdkmemorytexture.h"
|
||||
#include "gdkmemorytextureprivate.h"
|
||||
#include "gdkprofilerprivate.h"
|
||||
#include "gdktexturedownloaderprivate.h"
|
||||
#include "gdktexture.h"
|
||||
#include "gdktextureprivate.h"
|
||||
#include "gsk/gl/fp16private.h"
|
||||
#include <png.h>
|
||||
#include <stdio.h>
|
||||
@@ -296,12 +297,11 @@ gdk_save_png (GdkTexture *texture)
|
||||
png_info *info;
|
||||
png_io io = { NULL, 0, 0 };
|
||||
int width, height;
|
||||
int y;
|
||||
GdkMemoryFormat format;
|
||||
GdkTextureDownloader downloader;
|
||||
GBytes *bytes;
|
||||
gsize stride;
|
||||
const guchar *data;
|
||||
int y;
|
||||
GdkMemoryTexture *memtex;
|
||||
GdkMemoryFormat format;
|
||||
int png_format;
|
||||
int depth;
|
||||
|
||||
@@ -370,15 +370,11 @@ gdk_save_png (GdkTexture *texture)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gdk_texture_downloader_init (&downloader, texture);
|
||||
gdk_texture_downloader_set_format (&downloader, format);
|
||||
bytes = gdk_texture_downloader_download_bytes (&downloader, &stride);
|
||||
gdk_texture_downloader_finish (&downloader);
|
||||
data = g_bytes_get_data (bytes, NULL);
|
||||
memtex = gdk_memory_texture_from_texture (texture, format);
|
||||
|
||||
if (sigsetjmp (png_jmpbuf (png), 1))
|
||||
{
|
||||
g_bytes_unref (bytes);
|
||||
g_object_unref (memtex);
|
||||
g_free (io.data);
|
||||
png_destroy_read_struct (&png, &info, NULL);
|
||||
return NULL;
|
||||
@@ -398,6 +394,8 @@ gdk_save_png (GdkTexture *texture)
|
||||
png_set_swap (png);
|
||||
#endif
|
||||
|
||||
data = gdk_memory_texture_get_data (memtex);
|
||||
stride = gdk_memory_texture_get_stride (memtex);
|
||||
for (y = 0; y < height; y++)
|
||||
png_write_row (png, data + y * stride);
|
||||
|
||||
@@ -405,7 +403,7 @@ gdk_save_png (GdkTexture *texture)
|
||||
|
||||
png_destroy_write_struct (&png, &info);
|
||||
|
||||
g_bytes_unref (bytes);
|
||||
g_object_unref (memtex);
|
||||
|
||||
return g_bytes_new_take (io.data, io.size);
|
||||
}
|
||||
|
@@ -21,9 +21,10 @@
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include "gdkmemoryformatprivate.h"
|
||||
#include "gdkmemorytexture.h"
|
||||
#include "gdkmemorytextureprivate.h"
|
||||
#include "gdkprofilerprivate.h"
|
||||
#include "gdktexturedownloaderprivate.h"
|
||||
#include "gdktexture.h"
|
||||
#include "gdktextureprivate.h"
|
||||
|
||||
#include <tiffio.h>
|
||||
|
||||
@@ -259,12 +260,11 @@ GBytes *
|
||||
gdk_save_tiff (GdkTexture *texture)
|
||||
{
|
||||
TIFF *tif;
|
||||
int width, height;
|
||||
gsize stride;
|
||||
int width, height, stride;
|
||||
const guchar *line;
|
||||
const guchar *data;
|
||||
GBytes *bytes, *result = NULL;
|
||||
GdkTextureDownloader downloader;
|
||||
GBytes *result = NULL;
|
||||
GdkMemoryTexture *memtex;
|
||||
GdkMemoryFormat format;
|
||||
const FormatData *fdata = NULL;
|
||||
|
||||
@@ -292,11 +292,9 @@ gdk_save_tiff (GdkTexture *texture)
|
||||
TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
|
||||
TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
||||
|
||||
gdk_texture_downloader_init (&downloader, texture);
|
||||
gdk_texture_downloader_set_format (&downloader, fdata->format);
|
||||
bytes = gdk_texture_downloader_download_bytes (&downloader, &stride);
|
||||
gdk_texture_downloader_finish (&downloader);
|
||||
data = g_bytes_get_data (bytes, NULL);
|
||||
memtex = gdk_memory_texture_from_texture (texture, fdata->format);
|
||||
data = gdk_memory_texture_get_data (memtex);
|
||||
stride = gdk_memory_texture_get_stride (memtex);
|
||||
|
||||
line = (const guchar *)data;
|
||||
for (int y = 0; y < height; y++)
|
||||
@@ -304,7 +302,7 @@ gdk_save_tiff (GdkTexture *texture)
|
||||
if (TIFFWriteScanline (tif, (void *)line, y, 0) == -1)
|
||||
{
|
||||
TIFFClose (tif);
|
||||
g_bytes_unref (bytes);
|
||||
g_object_unref (memtex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -316,7 +314,7 @@ gdk_save_tiff (GdkTexture *texture)
|
||||
|
||||
g_assert (result);
|
||||
|
||||
g_bytes_unref (bytes);
|
||||
g_object_unref (memtex);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@@ -27,12 +27,10 @@
|
||||
#import "GdkMacosView.h"
|
||||
#import "GdkMacosWindow.h"
|
||||
|
||||
#include "gdkmacosclipboard-private.h"
|
||||
#include "gdkmacosdisplay-private.h"
|
||||
#include "gdkmacosdrag-private.h"
|
||||
#include "gdkmacosdrop-private.h"
|
||||
#include "gdkmacoseventsource-private.h"
|
||||
#include "gdkmacosmonitor-private.h"
|
||||
#include "gdkmacospasteboard-private.h"
|
||||
#include "gdkmacossurface-private.h"
|
||||
#include "gdkmacospopupsurface-private.h"
|
||||
#include "gdkmacostoplevelsurface-private.h"
|
||||
@@ -146,7 +144,7 @@ typedef NSString *CALayerContentsGravity;
|
||||
*
|
||||
* TODO: Can we improve grab breaking to fix this?
|
||||
*/
|
||||
_gdk_macos_display_send_event ([self gdkDisplay], event);
|
||||
_gdk_macos_display_send_button_event ([self gdkDisplay], event);
|
||||
|
||||
_gdk_macos_display_break_all_grabs (GDK_MACOS_DISPLAY (display), time);
|
||||
|
||||
@@ -248,7 +246,7 @@ typedef NSString *CALayerContentsGravity;
|
||||
[view release];
|
||||
|
||||
/* TODO: We might want to make this more extensible at some point */
|
||||
_gdk_macos_pasteboard_register_drag_types (self);
|
||||
_gdk_macos_clipboard_register_drag_types (self);
|
||||
|
||||
return self;
|
||||
}
|
||||
@@ -670,61 +668,7 @@ typedef NSString *CALayerContentsGravity;
|
||||
}
|
||||
|
||||
// NSDraggingSource protocol
|
||||
|
||||
- (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context
|
||||
{
|
||||
NSInteger sequence_number = [session draggingSequenceNumber];
|
||||
GdkDisplay *display = gdk_surface_get_display (GDK_SURFACE (gdk_surface));
|
||||
GdkDrag *drag = _gdk_macos_display_find_drag (GDK_MACOS_DISPLAY (display), sequence_number);
|
||||
GdkModifierType state = _gdk_macos_display_get_current_keyboard_modifiers (GDK_MACOS_DISPLAY (display));
|
||||
|
||||
_gdk_macos_drag_set_actions (GDK_MACOS_DRAG (drag), state);
|
||||
|
||||
return _gdk_macos_drag_operation (GDK_MACOS_DRAG (drag));
|
||||
}
|
||||
|
||||
- (void)draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint)screenPoint
|
||||
{
|
||||
NSInteger sequence_number = [session draggingSequenceNumber];
|
||||
GdkDisplay *display = gdk_surface_get_display (GDK_SURFACE (gdk_surface));
|
||||
GdkDrag *drag = _gdk_macos_display_find_drag (GDK_MACOS_DISPLAY (display), sequence_number);
|
||||
int x, y;
|
||||
|
||||
_gdk_macos_display_from_display_coords (GDK_MACOS_DISPLAY (display), screenPoint.x, screenPoint.y, &x, &y);
|
||||
_gdk_macos_drag_set_start_position (GDK_MACOS_DRAG (drag), x, y);
|
||||
_gdk_macos_drag_surface_move (GDK_MACOS_DRAG (drag), x, y);
|
||||
}
|
||||
|
||||
- (void)draggingSession:(NSDraggingSession *)session movedToPoint:(NSPoint)screenPoint
|
||||
{
|
||||
NSInteger sequence_number = [session draggingSequenceNumber];
|
||||
GdkMacosDisplay *display = GDK_MACOS_DISPLAY (gdk_surface_get_display (GDK_SURFACE (gdk_surface)));
|
||||
GdkDrag *drag = _gdk_macos_display_find_drag (GDK_MACOS_DISPLAY (display), sequence_number);
|
||||
int x, y;
|
||||
|
||||
_gdk_macos_display_send_event (display, [NSApp currentEvent]);
|
||||
|
||||
_gdk_macos_display_from_display_coords (display, screenPoint.x, screenPoint.y, &x, &y);
|
||||
_gdk_macos_drag_surface_move (GDK_MACOS_DRAG (drag), x, y);
|
||||
}
|
||||
|
||||
- (void)draggingSession:(NSDraggingSession *)session endedAtPoint:(NSPoint)screenPoint operation:(NSDragOperation)operation
|
||||
{
|
||||
NSInteger sequence_number = [session draggingSequenceNumber];
|
||||
GdkMacosDisplay *display = GDK_MACOS_DISPLAY (gdk_surface_get_display (GDK_SURFACE (gdk_surface)));
|
||||
GdkDrag *drag = _gdk_macos_display_find_drag (display, sequence_number);
|
||||
|
||||
_gdk_macos_display_send_event (display, [NSApp currentEvent]);
|
||||
gdk_drag_set_selected_action (drag, _gdk_macos_drag_ns_operation_to_action (operation));
|
||||
|
||||
if (gdk_drag_get_selected_action (drag) != 0)
|
||||
g_signal_emit_by_name (drag, "drop-performed");
|
||||
else
|
||||
gdk_drag_cancel (drag, GDK_DRAG_CANCEL_NO_TARGET);
|
||||
|
||||
_gdk_macos_display_set_drag (display, [session draggingSequenceNumber], NULL);
|
||||
}
|
||||
|
||||
// ...
|
||||
// end
|
||||
|
||||
-(void)setStyleMask:(NSWindowStyleMask)styleMask
|
||||
|
@@ -32,7 +32,7 @@
|
||||
|
||||
#define GDK_IS_MACOS_WINDOW(obj) ([obj isKindOfClass:[GdkMacosWindow class]])
|
||||
|
||||
@interface GdkMacosWindow : NSWindow <NSDraggingSource, NSDraggingDestination> {
|
||||
@interface GdkMacosWindow : NSWindow {
|
||||
GdkMacosSurface *gdk_surface;
|
||||
|
||||
BOOL inMove;
|
||||
|
@@ -24,7 +24,6 @@
|
||||
|
||||
#include "gdkclipboardprivate.h"
|
||||
#include "gdkmacosdisplay-private.h"
|
||||
#include "gdkmacospasteboard-private.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@@ -42,6 +41,30 @@ NSPasteboardType _gdk_macos_clipboard_to_ns_type (const char
|
||||
NSPasteboardType *alternate);
|
||||
const char *_gdk_macos_clipboard_from_ns_type (NSPasteboardType ns_type);
|
||||
void _gdk_macos_clipboard_register_drag_types (NSWindow *window);
|
||||
GdkContentFormats *_gdk_macos_pasteboard_load_formats (NSPasteboard *pasteboard);
|
||||
void _gdk_macos_pasteboard_read_async (GObject *object,
|
||||
NSPasteboard *pasteboard,
|
||||
GdkContentFormats *formats,
|
||||
int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
GInputStream *_gdk_macos_pasteboard_read_finish (GObject *object,
|
||||
GAsyncResult *result,
|
||||
const char **out_mime_type,
|
||||
GError **error);
|
||||
|
||||
@interface GdkMacosClipboardDataProvider : NSObject <NSPasteboardItemDataProvider>
|
||||
{
|
||||
GCancellable *cancellable;
|
||||
GdkClipboard *clipboard;
|
||||
char **mimeTypes;
|
||||
}
|
||||
|
||||
-(id)initClipboard:(GdkClipboard *)gdkClipboard mimetypes:(const char * const *)mime_types;
|
||||
-(NSArray<NSPasteboardType> *)types;
|
||||
|
||||
@end
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@@ -22,7 +22,6 @@
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "gdkmacosclipboard-private.h"
|
||||
#include "gdkmacospasteboard-private.h"
|
||||
#include "gdkmacosutils-private.h"
|
||||
#include "gdkprivate.h"
|
||||
|
||||
@@ -33,8 +32,163 @@ struct _GdkMacosClipboard
|
||||
NSInteger last_change_count;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GMemoryOutputStream *stream;
|
||||
NSPasteboardItem *item;
|
||||
NSPasteboardType type;
|
||||
GMainContext *main_context;
|
||||
guint done : 1;
|
||||
} WriteRequest;
|
||||
|
||||
enum {
|
||||
TYPE_STRING,
|
||||
TYPE_PBOARD,
|
||||
TYPE_URL,
|
||||
TYPE_FILE_URL,
|
||||
TYPE_COLOR,
|
||||
TYPE_TIFF,
|
||||
TYPE_PNG,
|
||||
TYPE_LAST
|
||||
};
|
||||
|
||||
#define PTYPE(k) (get_pasteboard_type(TYPE_##k))
|
||||
|
||||
static NSPasteboardType pasteboard_types[TYPE_LAST];
|
||||
|
||||
G_DEFINE_TYPE (GdkMacosClipboard, _gdk_macos_clipboard, GDK_TYPE_CLIPBOARD)
|
||||
|
||||
static NSPasteboardType
|
||||
get_pasteboard_type (int type)
|
||||
{
|
||||
static gsize initialized = FALSE;
|
||||
|
||||
g_assert (type >= 0);
|
||||
g_assert (type < TYPE_LAST);
|
||||
|
||||
if (g_once_init_enter (&initialized))
|
||||
{
|
||||
pasteboard_types[TYPE_PNG] = NSPasteboardTypePNG;
|
||||
pasteboard_types[TYPE_STRING] = NSPasteboardTypeString;
|
||||
pasteboard_types[TYPE_TIFF] = NSPasteboardTypeTIFF;
|
||||
pasteboard_types[TYPE_COLOR] = NSPasteboardTypeColor;
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
pasteboard_types[TYPE_PBOARD] = NSStringPboardType;
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
#ifdef AVAILABLE_MAC_OS_X_VERSION_10_13_AND_LATER
|
||||
pasteboard_types[TYPE_URL] = NSPasteboardTypeURL;
|
||||
pasteboard_types[TYPE_FILE_URL] = NSPasteboardTypeFileURL;
|
||||
#else
|
||||
pasteboard_types[TYPE_URL] = [[NSString alloc] initWithUTF8String:"public.url"];
|
||||
pasteboard_types[TYPE_FILE_URL] = [[NSString alloc] initWithUTF8String:"public.file-url"];
|
||||
#endif
|
||||
|
||||
g_once_init_leave (&initialized, TRUE);
|
||||
}
|
||||
|
||||
return pasteboard_types[type];
|
||||
}
|
||||
|
||||
static void
|
||||
write_request_free (WriteRequest *wr)
|
||||
{
|
||||
g_clear_pointer (&wr->main_context, g_main_context_unref);
|
||||
g_clear_object (&wr->stream);
|
||||
[wr->item release];
|
||||
g_slice_free (WriteRequest, wr);
|
||||
}
|
||||
|
||||
const char *
|
||||
_gdk_macos_clipboard_from_ns_type (NSPasteboardType type)
|
||||
{
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
||||
|
||||
if ([type isEqualToString:PTYPE(STRING)] ||
|
||||
[type isEqualToString:PTYPE(PBOARD)])
|
||||
return g_intern_string ("text/plain;charset=utf-8");
|
||||
else if ([type isEqualToString:PTYPE(URL)] ||
|
||||
[type isEqualToString:PTYPE(FILE_URL)])
|
||||
return g_intern_string ("text/uri-list");
|
||||
else if ([type isEqualToString:PTYPE(COLOR)])
|
||||
return g_intern_string ("application/x-color");
|
||||
else if ([type isEqualToString:PTYPE(TIFF)])
|
||||
return g_intern_string ("image/tiff");
|
||||
else if ([type isEqualToString:PTYPE(PNG)])
|
||||
return g_intern_string ("image/png");
|
||||
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NSPasteboardType
|
||||
_gdk_macos_clipboard_to_ns_type (const char *mime_type,
|
||||
NSPasteboardType *alternate)
|
||||
{
|
||||
if (alternate)
|
||||
*alternate = NULL;
|
||||
|
||||
if (g_strcmp0 (mime_type, "text/plain;charset=utf-8") == 0)
|
||||
{
|
||||
return PTYPE(STRING);
|
||||
}
|
||||
else if (g_strcmp0 (mime_type, "text/uri-list") == 0)
|
||||
{
|
||||
if (alternate)
|
||||
*alternate = PTYPE(URL);
|
||||
return PTYPE(FILE_URL);
|
||||
}
|
||||
else if (g_strcmp0 (mime_type, "application/x-color") == 0)
|
||||
{
|
||||
return PTYPE(COLOR);
|
||||
}
|
||||
else if (g_strcmp0 (mime_type, "image/tiff") == 0)
|
||||
{
|
||||
return PTYPE(TIFF);
|
||||
}
|
||||
else if (g_strcmp0 (mime_type, "image/png") == 0)
|
||||
{
|
||||
return PTYPE(PNG);
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
static void
|
||||
populate_content_formats (GdkContentFormatsBuilder *builder,
|
||||
NSPasteboardType type)
|
||||
{
|
||||
const char *mime_type;
|
||||
|
||||
g_return_if_fail (builder != NULL);
|
||||
g_return_if_fail (type != NULL);
|
||||
|
||||
mime_type = _gdk_macos_clipboard_from_ns_type (type);
|
||||
|
||||
if (mime_type != NULL)
|
||||
gdk_content_formats_builder_add_mime_type (builder, mime_type);
|
||||
}
|
||||
|
||||
static GdkContentFormats *
|
||||
load_offer_formats (NSPasteboard *pasteboard)
|
||||
{
|
||||
GDK_BEGIN_MACOS_ALLOC_POOL;
|
||||
|
||||
GdkContentFormatsBuilder *builder;
|
||||
GdkContentFormats *formats;
|
||||
|
||||
builder = gdk_content_formats_builder_new ();
|
||||
for (NSPasteboardType type in [pasteboard types])
|
||||
populate_content_formats (builder, type);
|
||||
formats = gdk_content_formats_builder_free_to_formats (builder);
|
||||
|
||||
GDK_END_MACOS_ALLOC_POOL;
|
||||
|
||||
return g_steal_pointer (&formats);
|
||||
}
|
||||
|
||||
static void
|
||||
_gdk_macos_clipboard_load_contents (GdkMacosClipboard *self)
|
||||
{
|
||||
@@ -45,13 +199,22 @@ _gdk_macos_clipboard_load_contents (GdkMacosClipboard *self)
|
||||
|
||||
change_count = [self->pasteboard changeCount];
|
||||
|
||||
formats = _gdk_macos_pasteboard_load_formats (self->pasteboard);
|
||||
formats = load_offer_formats (self->pasteboard);
|
||||
gdk_clipboard_claim_remote (GDK_CLIPBOARD (self), formats);
|
||||
gdk_content_formats_unref (formats);
|
||||
|
||||
self->last_change_count = change_count;
|
||||
}
|
||||
|
||||
static GInputStream *
|
||||
create_stream_from_nsdata (NSData *data)
|
||||
{
|
||||
const guint8 *bytes = [data bytes];
|
||||
gsize len = [data length];
|
||||
|
||||
return g_memory_input_stream_new_from_data (g_memdup2 (bytes, len), len, g_free);
|
||||
}
|
||||
|
||||
static void
|
||||
_gdk_macos_clipboard_read_async (GdkClipboard *clipboard,
|
||||
GdkContentFormats *formats,
|
||||
@@ -82,26 +245,34 @@ static void
|
||||
_gdk_macos_clipboard_send_to_pasteboard (GdkMacosClipboard *self,
|
||||
GdkContentProvider *content)
|
||||
{
|
||||
GdkMacosPasteboardItem *item;
|
||||
NSArray<NSPasteboardItem *> *items;
|
||||
|
||||
g_assert (GDK_IS_MACOS_CLIPBOARD (self));
|
||||
g_assert (GDK_IS_CONTENT_PROVIDER (content));
|
||||
|
||||
if (self->pasteboard == NULL)
|
||||
return;
|
||||
|
||||
GDK_BEGIN_MACOS_ALLOC_POOL;
|
||||
|
||||
item = [[GdkMacosPasteboardItem alloc] initForClipboard:GDK_CLIPBOARD (self) withContentProvider:content];
|
||||
items = [NSArray arrayWithObject:item];
|
||||
GdkMacosClipboardDataProvider *dataProvider;
|
||||
GdkContentFormats *serializable;
|
||||
NSPasteboardItem *item;
|
||||
const char * const *mime_types;
|
||||
gsize n_mime_types;
|
||||
|
||||
g_return_if_fail (GDK_IS_MACOS_CLIPBOARD (self));
|
||||
g_return_if_fail (GDK_IS_CONTENT_PROVIDER (content));
|
||||
|
||||
serializable = gdk_content_provider_ref_storable_formats (content);
|
||||
serializable = gdk_content_formats_union_serialize_mime_types (serializable);
|
||||
mime_types = gdk_content_formats_get_mime_types (serializable, &n_mime_types);
|
||||
|
||||
dataProvider = [[GdkMacosClipboardDataProvider alloc] initClipboard:GDK_CLIPBOARD (self)
|
||||
mimetypes:mime_types];
|
||||
item = [[NSPasteboardItem alloc] init];
|
||||
[item setDataProvider:dataProvider forTypes:[dataProvider types]];
|
||||
|
||||
[self->pasteboard clearContents];
|
||||
if ([self->pasteboard writeObjects:items] == NO)
|
||||
g_warning ("Failed to send clipboard to pasteboard");
|
||||
if ([self->pasteboard writeObjects:[NSArray arrayWithObject:item]] == NO)
|
||||
g_warning ("Failed to write object to pasteboard");
|
||||
|
||||
self->last_change_count = [self->pasteboard changeCount];
|
||||
|
||||
g_clear_pointer (&serializable, gdk_content_formats_unref);
|
||||
|
||||
GDK_END_MACOS_ALLOC_POOL;
|
||||
}
|
||||
|
||||
@@ -194,3 +365,305 @@ _gdk_macos_clipboard_check_externally_modified (GdkMacosClipboard *self)
|
||||
if ([self->pasteboard changeCount] != self->last_change_count)
|
||||
_gdk_macos_clipboard_load_contents (self);
|
||||
}
|
||||
|
||||
@implementation GdkMacosClipboardDataProvider
|
||||
|
||||
-(id)initClipboard:(GdkClipboard *)gdkClipboard mimetypes:(const char * const *)mime_types;
|
||||
{
|
||||
[super init];
|
||||
|
||||
self->mimeTypes = g_strdupv ((char **)mime_types);
|
||||
self->clipboard = g_object_ref (gdkClipboard);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
g_cancellable_cancel (self->cancellable);
|
||||
|
||||
g_clear_pointer (&self->mimeTypes, g_strfreev);
|
||||
g_clear_object (&self->clipboard);
|
||||
g_clear_object (&self->cancellable);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(void)pasteboardFinishedWithDataProvider:(NSPasteboard *)pasteboard
|
||||
{
|
||||
g_clear_object (&self->clipboard);
|
||||
}
|
||||
|
||||
-(NSArray<NSPasteboardType> *)types
|
||||
{
|
||||
NSMutableArray *ret = [[NSMutableArray alloc] init];
|
||||
|
||||
for (guint i = 0; self->mimeTypes[i]; i++)
|
||||
{
|
||||
const char *mime_type = self->mimeTypes[i];
|
||||
NSPasteboardType type;
|
||||
NSPasteboardType alternate = nil;
|
||||
|
||||
if ((type = _gdk_macos_clipboard_to_ns_type (mime_type, &alternate)))
|
||||
{
|
||||
[ret addObject:type];
|
||||
if (alternate)
|
||||
[ret addObject:alternate];
|
||||
}
|
||||
}
|
||||
|
||||
return g_steal_pointer (&ret);
|
||||
}
|
||||
|
||||
static void
|
||||
on_data_ready_cb (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GDK_BEGIN_MACOS_ALLOC_POOL;
|
||||
|
||||
GdkClipboard *clipboard = (GdkClipboard *)object;
|
||||
WriteRequest *wr = user_data;
|
||||
GError *error = NULL;
|
||||
NSData *data = nil;
|
||||
|
||||
g_assert (GDK_IS_CLIPBOARD (clipboard));
|
||||
g_assert (G_IS_ASYNC_RESULT (result));
|
||||
g_assert (wr != NULL);
|
||||
g_assert (G_IS_MEMORY_OUTPUT_STREAM (wr->stream));
|
||||
g_assert ([wr->item isKindOfClass:[NSPasteboardItem class]]);
|
||||
|
||||
if (gdk_clipboard_write_finish (clipboard, result, &error))
|
||||
{
|
||||
gsize size;
|
||||
gpointer bytes;
|
||||
|
||||
g_output_stream_close (G_OUTPUT_STREAM (wr->stream), NULL, NULL);
|
||||
|
||||
size = g_memory_output_stream_get_data_size (wr->stream);
|
||||
bytes = g_memory_output_stream_steal_data (wr->stream);
|
||||
data = [[NSData alloc] initWithBytesNoCopy:bytes
|
||||
length:size
|
||||
deallocator:^(void *alloc, NSUInteger length) { g_free (alloc); }];
|
||||
}
|
||||
else
|
||||
{
|
||||
g_warning ("Failed to serialize clipboard contents: %s",
|
||||
error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
[wr->item setData:data forType:wr->type];
|
||||
|
||||
wr->done = TRUE;
|
||||
|
||||
GDK_END_MACOS_ALLOC_POOL;
|
||||
}
|
||||
|
||||
-(void) pasteboard:(NSPasteboard *)pasteboard
|
||||
item:(NSPasteboardItem *)item
|
||||
provideDataForType:(NSPasteboardType)type
|
||||
{
|
||||
const char *mime_type = _gdk_macos_clipboard_from_ns_type (type);
|
||||
GMainContext *main_context = g_main_context_default ();
|
||||
WriteRequest *wr;
|
||||
|
||||
if (self->clipboard == NULL || mime_type == NULL)
|
||||
{
|
||||
[item setData:[NSData data] forType:type];
|
||||
return;
|
||||
}
|
||||
|
||||
wr = g_slice_new0 (WriteRequest);
|
||||
wr->item = [item retain];
|
||||
wr->stream = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new_resizable ());
|
||||
wr->type = type;
|
||||
wr->main_context = g_main_context_ref (main_context);
|
||||
wr->done = FALSE;
|
||||
|
||||
gdk_clipboard_write_async (self->clipboard,
|
||||
mime_type,
|
||||
G_OUTPUT_STREAM (wr->stream),
|
||||
G_PRIORITY_DEFAULT,
|
||||
self->cancellable,
|
||||
on_data_ready_cb,
|
||||
wr);
|
||||
|
||||
/* We're forced to provide data synchronously via this API
|
||||
* so we must block on the main loop. Using another main loop
|
||||
* than the default tends to get us locked up here, so that is
|
||||
* what we'll do for now.
|
||||
*/
|
||||
while (!wr->done)
|
||||
g_main_context_iteration (wr->main_context, TRUE);
|
||||
|
||||
write_request_free (wr);
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_macos_clipboard_register_drag_types (NSWindow *window)
|
||||
{
|
||||
[window registerForDraggedTypes:[NSArray arrayWithObjects:PTYPE(STRING),
|
||||
PTYPE(PBOARD),
|
||||
PTYPE(URL),
|
||||
PTYPE(FILE_URL),
|
||||
PTYPE(COLOR),
|
||||
PTYPE(TIFF),
|
||||
PTYPE(PNG),
|
||||
nil]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
GdkContentFormats *
|
||||
_gdk_macos_pasteboard_load_formats (NSPasteboard *pasteboard)
|
||||
{
|
||||
return load_offer_formats (pasteboard);
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_macos_pasteboard_read_async (GObject *object,
|
||||
NSPasteboard *pasteboard,
|
||||
GdkContentFormats *formats,
|
||||
int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GDK_BEGIN_MACOS_ALLOC_POOL;
|
||||
|
||||
GdkContentFormats *offer_formats = NULL;
|
||||
const char *mime_type;
|
||||
GInputStream *stream = NULL;
|
||||
GTask *task = NULL;
|
||||
|
||||
g_assert (G_IS_OBJECT (object));
|
||||
g_assert (pasteboard != NULL);
|
||||
g_assert (formats != NULL);
|
||||
|
||||
task = g_task_new (object, cancellable, callback, user_data);
|
||||
g_task_set_source_tag (task, _gdk_macos_pasteboard_read_async);
|
||||
g_task_set_priority (task, io_priority);
|
||||
|
||||
offer_formats = load_offer_formats (pasteboard);
|
||||
mime_type = gdk_content_formats_match_mime_type (formats, offer_formats);
|
||||
|
||||
if (mime_type == NULL)
|
||||
{
|
||||
g_task_return_new_error (task,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_NOT_SUPPORTED,
|
||||
"%s",
|
||||
_("No compatible transfer format found"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (strcmp (mime_type, "text/plain;charset=utf-8") == 0)
|
||||
{
|
||||
NSString *nsstr = [pasteboard stringForType:NSPasteboardTypeString];
|
||||
|
||||
if (nsstr != NULL)
|
||||
{
|
||||
const char *str = [nsstr UTF8String];
|
||||
stream = g_memory_input_stream_new_from_data (g_strdup (str),
|
||||
strlen (str) + 1,
|
||||
g_free);
|
||||
}
|
||||
}
|
||||
else if (strcmp (mime_type, "text/uri-list") == 0)
|
||||
{
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
||||
|
||||
if ([[pasteboard types] containsObject:PTYPE(FILE_URL)])
|
||||
{
|
||||
GString *str = g_string_new (NULL);
|
||||
NSArray *files = [pasteboard propertyListForType:NSFilenamesPboardType];
|
||||
gsize n_files = [files count];
|
||||
char *data;
|
||||
guint len;
|
||||
|
||||
for (gsize i = 0; i < n_files; ++i)
|
||||
{
|
||||
NSString* uriString = [files objectAtIndex:i];
|
||||
uriString = [@"file://" stringByAppendingString:uriString];
|
||||
uriString = [uriString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
g_string_append_printf (str,
|
||||
"%s\r\n",
|
||||
[uriString cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
}
|
||||
|
||||
len = str->len;
|
||||
data = g_string_free (str, FALSE);
|
||||
stream = g_memory_input_stream_new_from_data (data, len, g_free);
|
||||
}
|
||||
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS;
|
||||
}
|
||||
else if (strcmp (mime_type, "application/x-color") == 0)
|
||||
{
|
||||
NSColorSpace *colorspace;
|
||||
NSColor *nscolor;
|
||||
guint16 color[4];
|
||||
|
||||
colorspace = [NSColorSpace genericRGBColorSpace];
|
||||
nscolor = [[NSColor colorFromPasteboard:pasteboard]
|
||||
colorUsingColorSpace:colorspace];
|
||||
|
||||
color[0] = 0xffff * [nscolor redComponent];
|
||||
color[1] = 0xffff * [nscolor greenComponent];
|
||||
color[2] = 0xffff * [nscolor blueComponent];
|
||||
color[3] = 0xffff * [nscolor alphaComponent];
|
||||
|
||||
stream = g_memory_input_stream_new_from_data (g_memdup2 (&color, sizeof color),
|
||||
sizeof color,
|
||||
g_free);
|
||||
}
|
||||
else if (strcmp (mime_type, "image/tiff") == 0)
|
||||
{
|
||||
NSData *data = [pasteboard dataForType:PTYPE(TIFF)];
|
||||
stream = create_stream_from_nsdata (data);
|
||||
}
|
||||
else if (strcmp (mime_type, "image/png") == 0)
|
||||
{
|
||||
NSData *data = [pasteboard dataForType:PTYPE(PNG)];
|
||||
stream = create_stream_from_nsdata (data);
|
||||
}
|
||||
|
||||
if (stream != NULL)
|
||||
{
|
||||
g_task_set_task_data (task, g_strdup (mime_type), g_free);
|
||||
g_task_return_pointer (task, g_steal_pointer (&stream), g_object_unref);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_task_return_new_error (task,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
_("Failed to decode contents with mime-type of '%s'"),
|
||||
mime_type);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
g_clear_object (&task);
|
||||
g_clear_pointer (&offer_formats, gdk_content_formats_unref);
|
||||
|
||||
GDK_END_MACOS_ALLOC_POOL;
|
||||
}
|
||||
|
||||
GInputStream *
|
||||
_gdk_macos_pasteboard_read_finish (GObject *object,
|
||||
GAsyncResult *result,
|
||||
const char **out_mime_type,
|
||||
GError **error)
|
||||
{
|
||||
GTask *task = (GTask *)result;
|
||||
|
||||
g_assert (G_IS_OBJECT (object));
|
||||
g_assert (G_IS_TASK (task));
|
||||
|
||||
if (out_mime_type != NULL)
|
||||
*out_mime_type = g_strdup (g_task_get_task_data (task));
|
||||
|
||||
return g_task_propagate_pointer (task, error);
|
||||
}
|
||||
|
@@ -155,13 +155,12 @@ void _gdk_macos_display_surface_became_key (GdkMacosDisp
|
||||
GdkMacosSurface *surface);
|
||||
void _gdk_macos_display_clear_sorting (GdkMacosDisplay *self);
|
||||
const GList *_gdk_macos_display_get_surfaces (GdkMacosDisplay *self);
|
||||
void _gdk_macos_display_send_event (GdkMacosDisplay *self,
|
||||
void _gdk_macos_display_send_button_event (GdkMacosDisplay *self,
|
||||
NSEvent *nsevent);
|
||||
void _gdk_macos_display_warp_pointer (GdkMacosDisplay *self,
|
||||
int x,
|
||||
int y);
|
||||
NSEvent *_gdk_macos_display_get_nsevent (GdkEvent *event);
|
||||
NSEvent *_gdk_macos_display_get_last_nsevent (void);
|
||||
GdkDrag *_gdk_macos_display_find_drag (GdkMacosDisplay *self,
|
||||
NSInteger sequence_number);
|
||||
GdkDrop *_gdk_macos_display_find_drop (GdkMacosDisplay *self,
|
||||
|
@@ -723,85 +723,6 @@ fill_scroll_event (GdkMacosDisplay *self,
|
||||
return g_steal_pointer (&ret);
|
||||
}
|
||||
|
||||
|
||||
static GdkEvent *
|
||||
fill_event (GdkMacosDisplay *self,
|
||||
GdkMacosWindow *window,
|
||||
NSEvent *nsevent,
|
||||
int x,
|
||||
int y)
|
||||
{
|
||||
GdkMacosSurface *surface = [window gdkSurface];
|
||||
NSEventType event_type = [nsevent type];
|
||||
GdkEvent *ret = NULL;
|
||||
|
||||
switch ((int)event_type)
|
||||
{
|
||||
case NSEventTypeLeftMouseDown:
|
||||
case NSEventTypeRightMouseDown:
|
||||
case NSEventTypeOtherMouseDown:
|
||||
case NSEventTypeLeftMouseUp:
|
||||
case NSEventTypeRightMouseUp:
|
||||
case NSEventTypeOtherMouseUp:
|
||||
ret = fill_button_event (self, surface, nsevent, x, y);
|
||||
break;
|
||||
|
||||
case NSEventTypeLeftMouseDragged:
|
||||
case NSEventTypeRightMouseDragged:
|
||||
case NSEventTypeOtherMouseDragged:
|
||||
case NSEventTypeMouseMoved:
|
||||
ret = fill_motion_event (self, surface, nsevent, x, y);
|
||||
break;
|
||||
|
||||
case NSEventTypeMagnify:
|
||||
case NSEventTypeRotate:
|
||||
ret = fill_pinch_event (self, surface, nsevent, x, y);
|
||||
break;
|
||||
|
||||
case NSEventTypeMouseExited:
|
||||
case NSEventTypeMouseEntered:
|
||||
{
|
||||
GdkSeat *seat = gdk_display_get_default_seat (GDK_DISPLAY (self));
|
||||
GdkDevice *pointer = gdk_seat_get_pointer (seat);
|
||||
GdkDeviceGrabInfo *grab = _gdk_display_get_last_device_grab (GDK_DISPLAY (self), pointer);
|
||||
|
||||
if ([(GdkMacosWindow *)window isInManualResizeOrMove])
|
||||
{
|
||||
ret = GDK_MACOS_EVENT_DROP;
|
||||
}
|
||||
else if (grab == NULL || grab->owner_events)
|
||||
{
|
||||
if (event_type == NSEventTypeMouseExited)
|
||||
[[NSCursor arrowCursor] set];
|
||||
|
||||
ret = synthesize_crossing_event (self, surface, nsevent, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case NSEventTypeKeyDown:
|
||||
case NSEventTypeKeyUp:
|
||||
case NSEventTypeFlagsChanged: {
|
||||
GdkEventType type = _gdk_macos_keymap_get_event_type (nsevent);
|
||||
|
||||
if (type)
|
||||
ret = fill_key_event (self, surface, nsevent, type);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case NSEventTypeScrollWheel:
|
||||
ret = fill_scroll_event (self, surface, nsevent, x, y);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_mouse_button_press_event (NSEventType type)
|
||||
{
|
||||
@@ -1104,12 +1025,16 @@ find_surface_for_ns_event (GdkMacosDisplay *self,
|
||||
GdkMacosBaseView *view;
|
||||
GdkSurface *surface;
|
||||
NSPoint point;
|
||||
int x_tmp;
|
||||
int y_tmp;
|
||||
|
||||
g_assert (GDK_IS_MACOS_DISPLAY (self));
|
||||
g_assert (nsevent != NULL);
|
||||
g_assert (x != NULL);
|
||||
g_assert (y != NULL);
|
||||
|
||||
_gdk_macos_display_from_display_coords (self, point.x, point.y, &x_tmp, &y_tmp);
|
||||
|
||||
switch ((int)[nsevent type])
|
||||
{
|
||||
case NSEventTypeLeftMouseDown:
|
||||
@@ -1158,6 +1083,7 @@ _gdk_macos_display_translate (GdkMacosDisplay *self,
|
||||
GdkMacosWindow *window;
|
||||
NSEventType event_type;
|
||||
NSWindow *event_window;
|
||||
GdkEvent *ret = NULL;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
@@ -1265,15 +1191,79 @@ _gdk_macos_display_translate (GdkMacosDisplay *self,
|
||||
_gdk_macos_display_clear_sorting (self);
|
||||
}
|
||||
}
|
||||
return fill_event (self, window, nsevent, x, y);
|
||||
|
||||
switch ((int)event_type)
|
||||
{
|
||||
case NSEventTypeLeftMouseDown:
|
||||
case NSEventTypeRightMouseDown:
|
||||
case NSEventTypeOtherMouseDown:
|
||||
case NSEventTypeLeftMouseUp:
|
||||
case NSEventTypeRightMouseUp:
|
||||
case NSEventTypeOtherMouseUp:
|
||||
ret = fill_button_event (self, surface, nsevent, x, y);
|
||||
break;
|
||||
|
||||
case NSEventTypeLeftMouseDragged:
|
||||
case NSEventTypeRightMouseDragged:
|
||||
case NSEventTypeOtherMouseDragged:
|
||||
case NSEventTypeMouseMoved:
|
||||
ret = fill_motion_event (self, surface, nsevent, x, y);
|
||||
break;
|
||||
|
||||
case NSEventTypeMagnify:
|
||||
case NSEventTypeRotate:
|
||||
ret = fill_pinch_event (self, surface, nsevent, x, y);
|
||||
break;
|
||||
|
||||
case NSEventTypeMouseExited:
|
||||
case NSEventTypeMouseEntered:
|
||||
{
|
||||
GdkSeat *seat = gdk_display_get_default_seat (GDK_DISPLAY (self));
|
||||
GdkDevice *pointer = gdk_seat_get_pointer (seat);
|
||||
GdkDeviceGrabInfo *grab = _gdk_display_get_last_device_grab (GDK_DISPLAY (self), pointer);
|
||||
|
||||
if ([(GdkMacosWindow *)window isInManualResizeOrMove])
|
||||
{
|
||||
ret = GDK_MACOS_EVENT_DROP;
|
||||
}
|
||||
else if (grab == NULL)
|
||||
{
|
||||
if (event_type == NSEventTypeMouseExited)
|
||||
[[NSCursor arrowCursor] set];
|
||||
|
||||
ret = synthesize_crossing_event (self, surface, nsevent, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case NSEventTypeKeyDown:
|
||||
case NSEventTypeKeyUp:
|
||||
case NSEventTypeFlagsChanged: {
|
||||
GdkEventType type = _gdk_macos_keymap_get_event_type (nsevent);
|
||||
|
||||
if (type)
|
||||
ret = fill_key_event (self, surface, nsevent, type);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case NSEventTypeScrollWheel:
|
||||
ret = fill_scroll_event (self, surface, nsevent, x, y);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_macos_display_send_event (GdkMacosDisplay *self,
|
||||
NSEvent *nsevent)
|
||||
_gdk_macos_display_send_button_event (GdkMacosDisplay *self,
|
||||
NSEvent *nsevent)
|
||||
{
|
||||
GdkMacosSurface *surface;
|
||||
GdkMacosWindow *window;
|
||||
GdkEvent *event;
|
||||
int x;
|
||||
int y;
|
||||
@@ -1282,8 +1272,7 @@ _gdk_macos_display_send_event (GdkMacosDisplay *self,
|
||||
g_return_if_fail (nsevent != NULL);
|
||||
|
||||
if ((surface = find_surface_for_ns_event (self, nsevent, &x, &y)) &&
|
||||
(window = (GdkMacosWindow *)_gdk_macos_surface_get_native (surface)) &&
|
||||
(event = fill_event (self, window, nsevent, x, y)))
|
||||
(event = fill_button_event (self, surface, nsevent, x, y)))
|
||||
_gdk_windowing_got_event (GDK_DISPLAY (self),
|
||||
_gdk_event_queue_append (GDK_DISPLAY (self), event),
|
||||
event,
|
||||
|
@@ -1024,16 +1024,6 @@ _gdk_macos_display_get_nsevent (GdkEvent *event)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NSEvent *
|
||||
_gdk_macos_display_get_last_nsevent ()
|
||||
{
|
||||
const GdkToNSEventMap *map = g_queue_peek_tail (&event_map);
|
||||
if (map)
|
||||
return map->nsevent;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GdkDrag *
|
||||
_gdk_macos_display_find_drag (GdkMacosDisplay *self,
|
||||
NSInteger sequence_number)
|
||||
|
@@ -41,6 +41,7 @@ struct _GdkMacosDrag
|
||||
GdkDrag parent_instance;
|
||||
|
||||
GdkMacosDragSurface *drag_surface;
|
||||
GdkSeat *drag_seat;
|
||||
GdkCursor *cursor;
|
||||
|
||||
int hot_x;
|
||||
@@ -61,22 +62,8 @@ struct _GdkMacosDragClass
|
||||
GdkDragClass parent_class;
|
||||
};
|
||||
|
||||
GType gdk_macos_drag_get_type (void) G_GNUC_CONST;
|
||||
gboolean _gdk_macos_drag_begin (GdkMacosDrag *self,
|
||||
GdkContentProvider *content,
|
||||
GdkMacosWindow *window);
|
||||
NSDragOperation _gdk_macos_drag_operation (GdkMacosDrag *self);
|
||||
GdkDragAction _gdk_macos_drag_ns_operation_to_action
|
||||
(NSDragOperation operation);
|
||||
void _gdk_macos_drag_surface_move (GdkMacosDrag *self,
|
||||
int x_root,
|
||||
int y_root);
|
||||
void _gdk_macos_drag_set_start_position (GdkMacosDrag *self,
|
||||
int start_x,
|
||||
int start_y);
|
||||
void _gdk_macos_drag_set_actions (GdkMacosDrag *self,
|
||||
GdkModifierType mods);
|
||||
|
||||
GType gdk_macos_drag_get_type (void) G_GNUC_CONST;
|
||||
gboolean _gdk_macos_drag_begin (GdkMacosDrag *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@@ -25,7 +25,6 @@
|
||||
#include "gdkmacoscursor-private.h"
|
||||
#include "gdkmacosdisplay-private.h"
|
||||
#include "gdkmacosdragsurface-private.h"
|
||||
#include "gdkmacospasteboard-private.h"
|
||||
|
||||
#include "gdk/gdkdeviceprivate.h"
|
||||
#include "gdk/gdkeventsprivate.h"
|
||||
@@ -188,6 +187,47 @@ gdk_macos_drag_set_cursor (GdkDrag *drag,
|
||||
[nscursor set];
|
||||
}
|
||||
|
||||
static gboolean
|
||||
drag_grab (GdkMacosDrag *self)
|
||||
{
|
||||
GdkSeat *seat;
|
||||
|
||||
g_assert (GDK_IS_MACOS_DRAG (self));
|
||||
|
||||
seat = gdk_device_get_seat (gdk_drag_get_device (GDK_DRAG (self)));
|
||||
|
||||
if (gdk_seat_grab (seat,
|
||||
GDK_SURFACE (self->drag_surface),
|
||||
GDK_SEAT_CAPABILITY_ALL_POINTING,
|
||||
FALSE,
|
||||
self->cursor,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL) != GDK_GRAB_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
g_set_object (&self->drag_seat, seat);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
drag_ungrab (GdkMacosDrag *self)
|
||||
{
|
||||
GdkDisplay *display;
|
||||
|
||||
g_assert (GDK_IS_MACOS_DRAG (self));
|
||||
|
||||
if (self->drag_seat)
|
||||
{
|
||||
gdk_seat_ungrab (self->drag_seat);
|
||||
g_clear_object (&self->drag_seat);
|
||||
}
|
||||
|
||||
display = gdk_drag_get_display (GDK_DRAG (self));
|
||||
_gdk_macos_display_break_all_grabs (GDK_MACOS_DISPLAY (display), GDK_CURRENT_TIME);
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_macos_drag_cancel (GdkDrag *drag,
|
||||
GdkDragCancelReason reason)
|
||||
@@ -200,6 +240,7 @@ gdk_macos_drag_cancel (GdkDrag *drag,
|
||||
return;
|
||||
|
||||
self->cancelled = TRUE;
|
||||
drag_ungrab (self);
|
||||
gdk_drag_drop_done (drag, FALSE);
|
||||
}
|
||||
|
||||
@@ -212,6 +253,7 @@ gdk_macos_drag_drop_performed (GdkDrag *drag,
|
||||
g_assert (GDK_IS_MACOS_DRAG (self));
|
||||
|
||||
g_object_ref (self);
|
||||
drag_ungrab (self);
|
||||
g_signal_emit_by_name (drag, "dnd-finished");
|
||||
gdk_drag_drop_done (drag, TRUE);
|
||||
g_object_unref (self);
|
||||
@@ -274,6 +316,225 @@ gdk_drag_get_current_actions (GdkModifierType state,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_drag_update (GdkDrag *drag,
|
||||
double x_root,
|
||||
double y_root,
|
||||
GdkModifierType mods,
|
||||
guint32 evtime)
|
||||
{
|
||||
GdkMacosDrag *self = (GdkMacosDrag *)drag;
|
||||
GdkDragAction suggested_action;
|
||||
GdkDragAction possible_actions;
|
||||
|
||||
g_assert (GDK_IS_MACOS_DRAG (self));
|
||||
|
||||
self->last_x = x_root;
|
||||
self->last_y = y_root;
|
||||
|
||||
gdk_drag_get_current_actions (mods,
|
||||
GDK_BUTTON_PRIMARY,
|
||||
gdk_drag_get_actions (drag),
|
||||
&suggested_action,
|
||||
&possible_actions);
|
||||
|
||||
if (GDK_IS_MACOS_SURFACE (self->drag_surface))
|
||||
_gdk_macos_surface_move (GDK_MACOS_SURFACE (self->drag_surface),
|
||||
x_root - self->hot_x,
|
||||
y_root - self->hot_y);
|
||||
|
||||
if (!self->did_update)
|
||||
{
|
||||
self->start_x = self->last_x;
|
||||
self->start_y = self->last_y;
|
||||
self->did_update = TRUE;
|
||||
}
|
||||
|
||||
gdk_drag_set_actions (drag, possible_actions);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gdk_dnd_handle_motion_event (GdkDrag *drag,
|
||||
GdkEvent *event)
|
||||
{
|
||||
double x, y;
|
||||
int x_root, y_root;
|
||||
|
||||
g_assert (GDK_IS_MACOS_DRAG (drag));
|
||||
g_assert (event != NULL);
|
||||
|
||||
/* Ignore motion while doing zoomback */
|
||||
if (GDK_MACOS_DRAG (drag)->cancelled)
|
||||
return FALSE;
|
||||
|
||||
gdk_event_get_position (event, &x, &y);
|
||||
x_root = event->surface->x + x;
|
||||
y_root = event->surface->y + y;
|
||||
gdk_drag_update (drag, x_root, y_root,
|
||||
gdk_event_get_modifier_state (event),
|
||||
gdk_event_get_time (event));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gdk_dnd_handle_grab_broken_event (GdkDrag *drag,
|
||||
GdkEvent *event)
|
||||
{
|
||||
GdkMacosDrag *self = GDK_MACOS_DRAG (drag);
|
||||
gboolean is_implicit = gdk_grab_broken_event_get_implicit (event);
|
||||
GdkSurface *grab_surface = gdk_grab_broken_event_get_grab_surface (event);
|
||||
|
||||
/* Don't cancel if we break the implicit grab from the initial button_press. */
|
||||
if (is_implicit || grab_surface == (GdkSurface *)self->drag_surface)
|
||||
return FALSE;
|
||||
|
||||
if (gdk_event_get_device (event) != gdk_drag_get_device (drag))
|
||||
return FALSE;
|
||||
|
||||
gdk_drag_cancel (drag, GDK_DRAG_CANCEL_ERROR);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gdk_dnd_handle_button_event (GdkDrag *drag,
|
||||
GdkEvent *event)
|
||||
{
|
||||
GdkMacosDrag *self = GDK_MACOS_DRAG (drag);
|
||||
|
||||
g_assert (GDK_IS_MACOS_DRAG (self));
|
||||
g_assert (event != NULL);
|
||||
|
||||
#if 0
|
||||
/* FIXME: Check the button matches */
|
||||
if (event->button != self->button)
|
||||
return FALSE;
|
||||
#endif
|
||||
|
||||
if (gdk_drag_get_selected_action (drag) != 0)
|
||||
g_signal_emit_by_name (drag, "drop-performed");
|
||||
else
|
||||
gdk_drag_cancel (drag, GDK_DRAG_CANCEL_NO_TARGET);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gdk_dnd_handle_key_event (GdkDrag *drag,
|
||||
GdkEvent *event)
|
||||
{
|
||||
GdkMacosDrag *self = GDK_MACOS_DRAG (drag);
|
||||
GdkModifierType state;
|
||||
GdkDevice *pointer;
|
||||
GdkSeat *seat;
|
||||
int dx, dy;
|
||||
|
||||
dx = dy = 0;
|
||||
state = gdk_event_get_modifier_state (event);
|
||||
seat = gdk_event_get_seat (event);
|
||||
pointer = gdk_seat_get_pointer (seat);
|
||||
|
||||
if (event->event_type == GDK_KEY_PRESS)
|
||||
{
|
||||
guint keyval = gdk_key_event_get_keyval (event);
|
||||
|
||||
switch (keyval)
|
||||
{
|
||||
case GDK_KEY_Escape:
|
||||
gdk_drag_cancel (drag, GDK_DRAG_CANCEL_USER_CANCELLED);
|
||||
return TRUE;
|
||||
|
||||
case GDK_KEY_space:
|
||||
case GDK_KEY_Return:
|
||||
case GDK_KEY_ISO_Enter:
|
||||
case GDK_KEY_KP_Enter:
|
||||
case GDK_KEY_KP_Space:
|
||||
if (gdk_drag_get_selected_action (drag) != 0)
|
||||
g_signal_emit_by_name (drag, "drop-performed");
|
||||
else
|
||||
gdk_drag_cancel (drag, GDK_DRAG_CANCEL_NO_TARGET);
|
||||
|
||||
return TRUE;
|
||||
|
||||
case GDK_KEY_Up:
|
||||
case GDK_KEY_KP_Up:
|
||||
dy = (state & GDK_ALT_MASK) ? -BIG_STEP : -SMALL_STEP;
|
||||
break;
|
||||
|
||||
case GDK_KEY_Down:
|
||||
case GDK_KEY_KP_Down:
|
||||
dy = (state & GDK_ALT_MASK) ? BIG_STEP : SMALL_STEP;
|
||||
break;
|
||||
|
||||
case GDK_KEY_Left:
|
||||
case GDK_KEY_KP_Left:
|
||||
dx = (state & GDK_ALT_MASK) ? -BIG_STEP : -SMALL_STEP;
|
||||
break;
|
||||
|
||||
case GDK_KEY_Right:
|
||||
case GDK_KEY_KP_Right:
|
||||
dx = (state & GDK_ALT_MASK) ? BIG_STEP : SMALL_STEP;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* The state is not yet updated in the event, so we need
|
||||
* to query it here. We could use XGetModifierMapping, but
|
||||
* that would be overkill.
|
||||
*/
|
||||
gdk_macos_device_query_state (pointer, NULL, NULL, NULL, NULL, &state);
|
||||
|
||||
if (dx != 0 || dy != 0)
|
||||
{
|
||||
GdkDisplay *display = gdk_event_get_display ((GdkEvent *)event);
|
||||
|
||||
self->last_x += dx;
|
||||
self->last_y += dy;
|
||||
|
||||
_gdk_macos_display_warp_pointer (GDK_MACOS_DISPLAY (display),
|
||||
self->last_x,
|
||||
self->last_y);
|
||||
}
|
||||
|
||||
gdk_drag_update (drag,
|
||||
self->last_x, self->last_y,
|
||||
state,
|
||||
gdk_event_get_time (event));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gdk_macos_drag_handle_event (GdkDrag *drag,
|
||||
GdkEvent *event)
|
||||
{
|
||||
g_assert (GDK_IS_MACOS_DRAG (drag));
|
||||
g_assert (event != NULL);
|
||||
|
||||
switch ((guint) event->event_type)
|
||||
{
|
||||
case GDK_MOTION_NOTIFY:
|
||||
return gdk_dnd_handle_motion_event (drag, event);
|
||||
|
||||
case GDK_BUTTON_RELEASE:
|
||||
return gdk_dnd_handle_button_event (drag, event);
|
||||
|
||||
case GDK_KEY_PRESS:
|
||||
case GDK_KEY_RELEASE:
|
||||
return gdk_dnd_handle_key_event (drag, event);
|
||||
|
||||
case GDK_GRAB_BROKEN:
|
||||
return gdk_dnd_handle_grab_broken_event (drag, event);
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_macos_drag_finalize (GObject *object)
|
||||
{
|
||||
@@ -281,6 +542,11 @@ gdk_macos_drag_finalize (GObject *object)
|
||||
GdkMacosDragSurface *drag_surface = g_steal_pointer (&self->drag_surface);
|
||||
|
||||
g_clear_object (&self->cursor);
|
||||
if (self->drag_seat)
|
||||
{
|
||||
gdk_seat_ungrab (self->drag_seat);
|
||||
g_clear_object (&self->drag_seat);
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (gdk_macos_drag_parent_class)->finalize (object);
|
||||
|
||||
@@ -342,6 +608,7 @@ gdk_macos_drag_class_init (GdkMacosDragClass *klass)
|
||||
drag_class->set_cursor = gdk_macos_drag_set_cursor;
|
||||
drag_class->cancel = gdk_macos_drag_cancel;
|
||||
drag_class->drop_performed = gdk_macos_drag_drop_performed;
|
||||
drag_class->handle_event = gdk_macos_drag_handle_event;
|
||||
|
||||
properties [PROP_DRAG_SURFACE] =
|
||||
g_param_spec_object ("drag-surface", NULL, NULL,
|
||||
@@ -357,113 +624,11 @@ gdk_macos_drag_init (GdkMacosDrag *self)
|
||||
}
|
||||
|
||||
gboolean
|
||||
_gdk_macos_drag_begin (GdkMacosDrag *self,
|
||||
GdkContentProvider *content,
|
||||
GdkMacosWindow *window)
|
||||
_gdk_macos_drag_begin (GdkMacosDrag *self)
|
||||
{
|
||||
NSArray<NSDraggingItem *> *items;
|
||||
NSDraggingSession *session;
|
||||
NSPasteboardItem *item;
|
||||
NSEvent *nsevent;
|
||||
|
||||
g_return_val_if_fail (GDK_IS_MACOS_DRAG (self), FALSE);
|
||||
g_return_val_if_fail (GDK_IS_MACOS_WINDOW (window), FALSE);
|
||||
|
||||
GDK_BEGIN_MACOS_ALLOC_POOL;
|
||||
_gdk_macos_surface_show (GDK_MACOS_SURFACE (self->drag_surface));
|
||||
|
||||
item = [[GdkMacosPasteboardItem alloc] initForDrag:GDK_DRAG (self) withContentProvider:content];
|
||||
items = [NSArray arrayWithObject:item];
|
||||
nsevent = _gdk_macos_display_get_last_nsevent ();
|
||||
|
||||
session = [[window contentView] beginDraggingSessionWithItems:items
|
||||
event:nsevent
|
||||
source:window];
|
||||
|
||||
GDK_END_MACOS_ALLOC_POOL;
|
||||
|
||||
_gdk_macos_display_set_drag (GDK_MACOS_DISPLAY (gdk_drag_get_display (GDK_DRAG (self))),
|
||||
[session draggingSequenceNumber],
|
||||
GDK_DRAG (self));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
NSDragOperation
|
||||
_gdk_macos_drag_operation (GdkMacosDrag *self)
|
||||
{
|
||||
NSDragOperation operation = NSDragOperationNone;
|
||||
GdkDragAction actions;
|
||||
|
||||
g_return_val_if_fail (GDK_IS_MACOS_DRAG (self), NSDragOperationNone);
|
||||
|
||||
actions = gdk_drag_get_actions (GDK_DRAG (self));
|
||||
|
||||
if (actions & GDK_ACTION_LINK)
|
||||
operation |= NSDragOperationLink;
|
||||
|
||||
if (actions & GDK_ACTION_MOVE)
|
||||
operation |= NSDragOperationMove;
|
||||
|
||||
if (actions & GDK_ACTION_COPY)
|
||||
operation |= NSDragOperationCopy;
|
||||
|
||||
return operation;
|
||||
}
|
||||
|
||||
GdkDragAction
|
||||
_gdk_macos_drag_ns_operation_to_action (NSDragOperation operation)
|
||||
{
|
||||
if (operation & NSDragOperationCopy)
|
||||
return GDK_ACTION_COPY;
|
||||
if (operation & NSDragOperationMove)
|
||||
return GDK_ACTION_MOVE;
|
||||
if (operation & NSDragOperationLink)
|
||||
return GDK_ACTION_LINK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_macos_drag_surface_move (GdkMacosDrag *self,
|
||||
int x_root,
|
||||
int y_root)
|
||||
{
|
||||
g_return_if_fail (GDK_IS_MACOS_DRAG (self));
|
||||
|
||||
self->last_x = x_root;
|
||||
self->last_y = y_root;
|
||||
|
||||
if (GDK_IS_MACOS_SURFACE (self->drag_surface))
|
||||
_gdk_macos_surface_move (GDK_MACOS_SURFACE (self->drag_surface),
|
||||
x_root - self->hot_x,
|
||||
y_root - self->hot_y);
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_macos_drag_set_start_position (GdkMacosDrag *self,
|
||||
int start_x,
|
||||
int start_y)
|
||||
{
|
||||
g_return_if_fail (GDK_IS_MACOS_DRAG (self));
|
||||
|
||||
self->start_x = start_x;
|
||||
self->start_y = start_y;
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_macos_drag_set_actions (GdkMacosDrag *self,
|
||||
GdkModifierType mods)
|
||||
{
|
||||
GdkDragAction suggested_action;
|
||||
GdkDragAction possible_actions;
|
||||
|
||||
g_assert (GDK_IS_MACOS_DRAG (self));
|
||||
|
||||
gdk_drag_get_current_actions (mods,
|
||||
GDK_BUTTON_PRIMARY,
|
||||
gdk_drag_get_actions (GDK_DRAG (self)),
|
||||
&suggested_action,
|
||||
&possible_actions);
|
||||
|
||||
gdk_drag_set_selected_action (GDK_DRAG (self), suggested_action);
|
||||
gdk_drag_set_actions (GDK_DRAG (self), possible_actions);
|
||||
return drag_grab (self);
|
||||
}
|
||||
|
@@ -37,15 +37,11 @@
|
||||
/*
|
||||
* This file implementations integration between the GLib main loop and
|
||||
* the native system of the Core Foundation run loop and Cocoa event
|
||||
* handling. There are basically three different cases that we need to
|
||||
* handle:
|
||||
*
|
||||
* - the GLib main loop is in control. The application has called
|
||||
* gtk_main(), or is otherwise iterating the main loop.
|
||||
* - CFRunLoop is in control. We are in a modal operation such as window
|
||||
* resizing.
|
||||
* - CFRunLoop is running a nested loop. This happens when a drag-and-drop
|
||||
* operation has been initiated.
|
||||
* handling. There are basically two different cases that we need to
|
||||
* handle: either the GLib main loop is in control (the application
|
||||
* has called gtk_main(), or is otherwise iterating the main loop), or
|
||||
* CFRunLoop is in control (we are in a modal operation such as window
|
||||
* resizing or drag-and-drop.)
|
||||
*
|
||||
* When the GLib main loop is in control we integrate in native event
|
||||
* handling in two ways: first we add a GSource that handles checking
|
||||
@@ -61,23 +57,14 @@
|
||||
* stages of the GLib main loop (prepare, check, dispatch), and make the
|
||||
* appropriate calls into GLib.
|
||||
*
|
||||
* When initiating a drag operation, a nested CFRunLoop is executed.
|
||||
* The nested run loop is started when fetching a native event in our GLib
|
||||
* main loop. The application does not receive any events until the nested loop
|
||||
* is finished. We work around this by forwarding the
|
||||
* events that trigger the callbacks of the NSDraggingSource protocol.
|
||||
* The "run loop observer" is executing the GLib main loop stages as long as we're
|
||||
* in the nested run loop, as if CFRunLoop were in control.
|
||||
* See also GdkMacosWindow.
|
||||
*
|
||||
* All cases share a single problem: the macOS API’s don’t allow us to
|
||||
* Both cases share a single problem: the OS X API’s don’t allow us to
|
||||
* wait simultaneously for file descriptors and for events. So when we
|
||||
* need to do a blocking wait that includes file descriptor activity, we
|
||||
* push the actual work of calling select() to a helper thread (the
|
||||
* "select thread") and wait for native events in the main thread.
|
||||
*
|
||||
* The main known limitation of this code is that if a callback is triggered
|
||||
* via the macOS run loop while we are "polling" (in either case described
|
||||
* via the OS X run loop while we are "polling" (in either case described
|
||||
* above), iteration of the GLib main loop is not possible from within
|
||||
* that callback. If the programmer tries to do so explicitly, then they
|
||||
* will get a warning from GLib "main loop already active in another thread".
|
||||
@@ -653,23 +640,6 @@ _gdk_macos_event_source_get_pending (void)
|
||||
return event;
|
||||
}
|
||||
|
||||
static void
|
||||
_gdk_macos_event_source_queue_event (NSEvent *event)
|
||||
{
|
||||
/* Just used to wake us up; if an event and a FD arrived at the same
|
||||
* time; could have come from a previous iteration in some cases,
|
||||
* but the spurious wake up is harmless if a little inefficient.
|
||||
*/
|
||||
if (!event ||
|
||||
([event type] == NSEventTypeApplicationDefined &&
|
||||
[event subtype] == GDK_MACOS_EVENT_SUBTYPE_EVENTLOOP))
|
||||
return;
|
||||
|
||||
if (!current_events)
|
||||
current_events = g_queue_new ();
|
||||
g_queue_push_head (current_events, [event retain]);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gdk_macos_event_source_prepare (GSource *source,
|
||||
int *timeout)
|
||||
@@ -812,7 +782,23 @@ poll_func (GPollFD *ufds,
|
||||
if (last_ufds == ufds && n_ready < 0)
|
||||
n_ready = select_thread_collect_poll (ufds, nfds);
|
||||
|
||||
_gdk_macos_event_source_queue_event (event);
|
||||
if (event &&
|
||||
[event type] == NSEventTypeApplicationDefined &&
|
||||
[event subtype] == GDK_MACOS_EVENT_SUBTYPE_EVENTLOOP)
|
||||
{
|
||||
/* Just used to wake us up; if an event and a FD arrived at the same
|
||||
* time; could have come from a previous iteration in some cases,
|
||||
* but the spurious wake up is harmless if a little inefficient.
|
||||
*/
|
||||
event = NULL;
|
||||
}
|
||||
|
||||
if (event)
|
||||
{
|
||||
if (!current_events)
|
||||
current_events = g_queue_new ();
|
||||
g_queue_push_head (current_events, [event retain]);
|
||||
}
|
||||
|
||||
return n_ready;
|
||||
}
|
||||
@@ -1032,10 +1018,7 @@ run_loop_observer_callback (CFRunLoopObserverRef observer,
|
||||
break;
|
||||
}
|
||||
|
||||
/* DnD starts a nested runloop, or so it seems.
|
||||
If we have such a loop, we still want to run
|
||||
our idle handlers. */
|
||||
if (getting_events > 0 && current_loop_level < 2)
|
||||
if (getting_events > 0) /* Activity we triggered */
|
||||
return;
|
||||
|
||||
switch (activity)
|
||||
@@ -1059,6 +1042,7 @@ run_loop_observer_callback (CFRunLoopObserverRef observer,
|
||||
run_loop_exit ();
|
||||
break;
|
||||
case kCFRunLoopAllActivities:
|
||||
/* TODO: Do most of the above? */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@@ -548,14 +548,6 @@ gdk_macos_gl_context_clear_current (GdkGLContext *context)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gdk_macos_gl_context_is_current (GdkGLContext *context)
|
||||
{
|
||||
GdkMacosGLContext *self = GDK_MACOS_GL_CONTEXT (context);
|
||||
|
||||
return self->cgl_context == CGLGetCurrentContext ();
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gdk_macos_gl_context_make_current (GdkGLContext *context,
|
||||
gboolean surfaceless)
|
||||
@@ -647,7 +639,6 @@ gdk_macos_gl_context_class_init (GdkMacosGLContextClass *klass)
|
||||
|
||||
gl_class->get_damage = gdk_macos_gl_context_get_damage;
|
||||
gl_class->clear_current = gdk_macos_gl_context_clear_current;
|
||||
gl_class->is_current = gdk_macos_gl_context_is_current;
|
||||
gl_class->make_current = gdk_macos_gl_context_make_current;
|
||||
gl_class->realize = gdk_macos_gl_context_real_realize;
|
||||
gl_class->get_default_framebuffer = gdk_macos_gl_context_get_default_framebuffer;
|
||||
|
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2021 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*/
|
||||
|
||||
#ifndef __GDK_MACOS_PASTEBOARD_PRIVATE_H__
|
||||
#define __GDK_MACOS_PASTEBOARD_PRIVATE_H__
|
||||
|
||||
#include <AppKit/AppKit.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "gdkclipboardprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@interface GdkMacosPasteboardItemDataProvider : NSObject <NSPasteboardItemDataProvider>
|
||||
{
|
||||
GdkContentProvider *_contentProvider;
|
||||
GdkClipboard *_clipboard;
|
||||
GdkDrag *_drag;
|
||||
}
|
||||
|
||||
-(id)initForClipboard:(GdkClipboard *)clipboard withContentProvider:(GdkContentProvider *)contentProvider;
|
||||
-(id)initForDrag:(GdkDrag *)drag withContentProvider:(GdkContentProvider *)contentProvider;
|
||||
|
||||
@end
|
||||
|
||||
@interface GdkMacosPasteboardItem : NSPasteboardItem
|
||||
{
|
||||
GdkContentProvider *_contentProvider;
|
||||
GdkClipboard *_clipboard;
|
||||
GdkDrag *_drag;
|
||||
NSRect _draggingFrame;
|
||||
}
|
||||
|
||||
-(id)initForClipboard:(GdkClipboard *)clipboard withContentProvider:(GdkContentProvider *)contentProvider;
|
||||
-(id)initForDrag:(GdkDrag *)drag withContentProvider:(GdkContentProvider *)contentProvider;
|
||||
|
||||
@end
|
||||
|
||||
NSPasteboardType _gdk_macos_pasteboard_to_ns_type (const char *mime_type,
|
||||
NSPasteboardType *alternate);
|
||||
const char *_gdk_macos_pasteboard_from_ns_type (NSPasteboardType type);
|
||||
GdkContentFormats *_gdk_macos_pasteboard_load_formats (NSPasteboard *pasteboard);
|
||||
void _gdk_macos_pasteboard_register_drag_types (NSWindow *window);
|
||||
void _gdk_macos_pasteboard_read_async (GObject *object,
|
||||
NSPasteboard *pasteboard,
|
||||
GdkContentFormats *formats,
|
||||
int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
GInputStream *_gdk_macos_pasteboard_read_finish (GObject *object,
|
||||
GAsyncResult *result,
|
||||
const char **out_mime_type,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GDK_MACOS_PASTEBOARD_PRIVATE_H__ */
|
@@ -1,602 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2021 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "gdkdragprivate.h"
|
||||
#include "gdkmacospasteboard-private.h"
|
||||
#include "gdkmacosutils-private.h"
|
||||
|
||||
enum {
|
||||
TYPE_STRING,
|
||||
TYPE_PBOARD,
|
||||
TYPE_URL,
|
||||
TYPE_FILE_URL,
|
||||
TYPE_COLOR,
|
||||
TYPE_TIFF,
|
||||
TYPE_PNG,
|
||||
TYPE_LAST
|
||||
};
|
||||
|
||||
#define PTYPE(k) (get_pasteboard_type(TYPE_##k))
|
||||
|
||||
static NSPasteboardType pasteboard_types[TYPE_LAST];
|
||||
|
||||
static NSPasteboardType
|
||||
get_pasteboard_type (int type)
|
||||
{
|
||||
static gsize initialized = FALSE;
|
||||
|
||||
g_assert (type >= 0);
|
||||
g_assert (type < TYPE_LAST);
|
||||
|
||||
if (g_once_init_enter (&initialized))
|
||||
{
|
||||
pasteboard_types[TYPE_PNG] = NSPasteboardTypePNG;
|
||||
pasteboard_types[TYPE_STRING] = NSPasteboardTypeString;
|
||||
pasteboard_types[TYPE_TIFF] = NSPasteboardTypeTIFF;
|
||||
pasteboard_types[TYPE_COLOR] = NSPasteboardTypeColor;
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
pasteboard_types[TYPE_PBOARD] = NSStringPboardType;
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
#ifdef AVAILABLE_MAC_OS_X_VERSION_10_13_AND_LATER
|
||||
pasteboard_types[TYPE_URL] = NSPasteboardTypeURL;
|
||||
pasteboard_types[TYPE_FILE_URL] = NSPasteboardTypeFileURL;
|
||||
#else
|
||||
pasteboard_types[TYPE_URL] = [[NSString alloc] initWithUTF8String:"public.url"];
|
||||
pasteboard_types[TYPE_FILE_URL] = [[NSString alloc] initWithUTF8String:"public.file-url"];
|
||||
#endif
|
||||
|
||||
g_once_init_leave (&initialized, TRUE);
|
||||
}
|
||||
|
||||
return pasteboard_types[type];
|
||||
}
|
||||
|
||||
const char *
|
||||
_gdk_macos_pasteboard_from_ns_type (NSPasteboardType type)
|
||||
{
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
||||
|
||||
if ([type isEqualToString:PTYPE(STRING)] ||
|
||||
[type isEqualToString:PTYPE(PBOARD)])
|
||||
return g_intern_string ("text/plain;charset=utf-8");
|
||||
else if ([type isEqualToString:PTYPE(URL)] ||
|
||||
[type isEqualToString:PTYPE(FILE_URL)])
|
||||
return g_intern_string ("text/uri-list");
|
||||
else if ([type isEqualToString:PTYPE(COLOR)])
|
||||
return g_intern_string ("application/x-color");
|
||||
else if ([type isEqualToString:PTYPE(TIFF)])
|
||||
return g_intern_string ("image/tiff");
|
||||
else if ([type isEqualToString:PTYPE(PNG)])
|
||||
return g_intern_string ("image/png");
|
||||
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NSPasteboardType
|
||||
_gdk_macos_pasteboard_to_ns_type (const char *mime_type,
|
||||
NSPasteboardType *alternate)
|
||||
{
|
||||
if (alternate)
|
||||
*alternate = NULL;
|
||||
|
||||
if (g_strcmp0 (mime_type, "text/plain;charset=utf-8") == 0)
|
||||
{
|
||||
return PTYPE(STRING);
|
||||
}
|
||||
else if (g_strcmp0 (mime_type, "text/uri-list") == 0)
|
||||
{
|
||||
if (alternate)
|
||||
*alternate = PTYPE(URL);
|
||||
return PTYPE(FILE_URL);
|
||||
}
|
||||
else if (g_strcmp0 (mime_type, "application/x-color") == 0)
|
||||
{
|
||||
return PTYPE(COLOR);
|
||||
}
|
||||
else if (g_strcmp0 (mime_type, "image/tiff") == 0)
|
||||
{
|
||||
return PTYPE(TIFF);
|
||||
}
|
||||
else if (g_strcmp0 (mime_type, "image/png") == 0)
|
||||
{
|
||||
return PTYPE(PNG);
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
static void
|
||||
populate_content_formats (GdkContentFormatsBuilder *builder,
|
||||
NSPasteboardType type)
|
||||
{
|
||||
const char *mime_type;
|
||||
|
||||
g_assert (builder != NULL);
|
||||
g_assert (type != NULL);
|
||||
|
||||
if ((mime_type = _gdk_macos_pasteboard_from_ns_type (type)))
|
||||
gdk_content_formats_builder_add_mime_type (builder, mime_type);
|
||||
}
|
||||
|
||||
static GdkContentFormats *
|
||||
load_offer_formats (NSPasteboard *pasteboard)
|
||||
{
|
||||
GDK_BEGIN_MACOS_ALLOC_POOL;
|
||||
|
||||
GdkContentFormatsBuilder *builder;
|
||||
GdkContentFormats *formats;
|
||||
|
||||
builder = gdk_content_formats_builder_new ();
|
||||
for (NSPasteboardType type in [pasteboard types])
|
||||
populate_content_formats (builder, type);
|
||||
formats = gdk_content_formats_builder_free_to_formats (builder);
|
||||
|
||||
GDK_END_MACOS_ALLOC_POOL;
|
||||
|
||||
return g_steal_pointer (&formats);
|
||||
}
|
||||
|
||||
GdkContentFormats *
|
||||
_gdk_macos_pasteboard_load_formats (NSPasteboard *pasteboard)
|
||||
{
|
||||
return load_offer_formats (pasteboard);
|
||||
}
|
||||
|
||||
static GInputStream *
|
||||
create_stream_from_nsdata (NSData *data)
|
||||
{
|
||||
const guint8 *bytes = [data bytes];
|
||||
gsize len = [data length];
|
||||
|
||||
return g_memory_input_stream_new_from_data (g_memdup2 (bytes, len), len, g_free);
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_macos_pasteboard_read_async (GObject *object,
|
||||
NSPasteboard *pasteboard,
|
||||
GdkContentFormats *formats,
|
||||
int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GDK_BEGIN_MACOS_ALLOC_POOL;
|
||||
|
||||
GdkContentFormats *offer_formats = NULL;
|
||||
const char *mime_type;
|
||||
GInputStream *stream = NULL;
|
||||
GTask *task = NULL;
|
||||
|
||||
g_assert (G_IS_OBJECT (object));
|
||||
g_assert (pasteboard != NULL);
|
||||
g_assert (formats != NULL);
|
||||
|
||||
task = g_task_new (object, cancellable, callback, user_data);
|
||||
g_task_set_source_tag (task, _gdk_macos_pasteboard_read_async);
|
||||
g_task_set_priority (task, io_priority);
|
||||
|
||||
offer_formats = load_offer_formats (pasteboard);
|
||||
mime_type = gdk_content_formats_match_mime_type (formats, offer_formats);
|
||||
|
||||
if (mime_type == NULL)
|
||||
{
|
||||
g_task_return_new_error (task,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_NOT_SUPPORTED,
|
||||
"%s",
|
||||
_("No compatible transfer format found"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (strcmp (mime_type, "text/plain;charset=utf-8") == 0)
|
||||
{
|
||||
NSString *nsstr = [pasteboard stringForType:NSPasteboardTypeString];
|
||||
|
||||
if (nsstr != NULL)
|
||||
{
|
||||
const char *str = [nsstr UTF8String];
|
||||
stream = g_memory_input_stream_new_from_data (g_strdup (str),
|
||||
strlen (str) + 1,
|
||||
g_free);
|
||||
}
|
||||
}
|
||||
else if (strcmp (mime_type, "text/uri-list") == 0)
|
||||
{
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
||||
|
||||
if ([[pasteboard types] containsObject:PTYPE(FILE_URL)])
|
||||
{
|
||||
GString *str = g_string_new (NULL);
|
||||
NSArray *files = [pasteboard propertyListForType:NSFilenamesPboardType];
|
||||
gsize n_files = [files count];
|
||||
char *data;
|
||||
guint len;
|
||||
|
||||
for (gsize i = 0; i < n_files; ++i)
|
||||
{
|
||||
NSString* uriString = [files objectAtIndex:i];
|
||||
uriString = [@"file://" stringByAppendingString:uriString];
|
||||
uriString = [uriString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
g_string_append_printf (str,
|
||||
"%s\r\n",
|
||||
[uriString cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
}
|
||||
|
||||
len = str->len;
|
||||
data = g_string_free (str, FALSE);
|
||||
stream = g_memory_input_stream_new_from_data (data, len, g_free);
|
||||
}
|
||||
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS;
|
||||
}
|
||||
else if (strcmp (mime_type, "application/x-color") == 0)
|
||||
{
|
||||
NSColorSpace *colorspace;
|
||||
NSColor *nscolor;
|
||||
guint16 color[4];
|
||||
|
||||
colorspace = [NSColorSpace genericRGBColorSpace];
|
||||
nscolor = [[NSColor colorFromPasteboard:pasteboard]
|
||||
colorUsingColorSpace:colorspace];
|
||||
|
||||
color[0] = 0xffff * [nscolor redComponent];
|
||||
color[1] = 0xffff * [nscolor greenComponent];
|
||||
color[2] = 0xffff * [nscolor blueComponent];
|
||||
color[3] = 0xffff * [nscolor alphaComponent];
|
||||
|
||||
stream = g_memory_input_stream_new_from_data (g_memdup2 (&color, sizeof color),
|
||||
sizeof color,
|
||||
g_free);
|
||||
}
|
||||
else if (strcmp (mime_type, "image/tiff") == 0)
|
||||
{
|
||||
NSData *data = [pasteboard dataForType:PTYPE(TIFF)];
|
||||
stream = create_stream_from_nsdata (data);
|
||||
}
|
||||
else if (strcmp (mime_type, "image/png") == 0)
|
||||
{
|
||||
NSData *data = [pasteboard dataForType:PTYPE(PNG)];
|
||||
stream = create_stream_from_nsdata (data);
|
||||
}
|
||||
|
||||
if (stream != NULL)
|
||||
{
|
||||
g_task_set_task_data (task, g_strdup (mime_type), g_free);
|
||||
g_task_return_pointer (task, g_steal_pointer (&stream), g_object_unref);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_task_return_new_error (task,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
_("Failed to decode contents with mime-type of '%s'"),
|
||||
mime_type);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
g_clear_object (&task);
|
||||
g_clear_pointer (&offer_formats, gdk_content_formats_unref);
|
||||
|
||||
GDK_END_MACOS_ALLOC_POOL;
|
||||
}
|
||||
|
||||
GInputStream *
|
||||
_gdk_macos_pasteboard_read_finish (GObject *object,
|
||||
GAsyncResult *result,
|
||||
const char **out_mime_type,
|
||||
GError **error)
|
||||
{
|
||||
GTask *task = (GTask *)result;
|
||||
|
||||
g_assert (G_IS_OBJECT (object));
|
||||
g_assert (G_IS_TASK (task));
|
||||
|
||||
if (out_mime_type != NULL)
|
||||
*out_mime_type = g_strdup (g_task_get_task_data (task));
|
||||
|
||||
return g_task_propagate_pointer (task, error);
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_macos_pasteboard_register_drag_types (NSWindow *window)
|
||||
{
|
||||
[window registerForDraggedTypes:[NSArray arrayWithObjects:PTYPE(STRING),
|
||||
PTYPE(PBOARD),
|
||||
PTYPE(URL),
|
||||
PTYPE(FILE_URL),
|
||||
PTYPE(COLOR),
|
||||
PTYPE(TIFF),
|
||||
PTYPE(PNG),
|
||||
nil]];
|
||||
}
|
||||
|
||||
@implementation GdkMacosPasteboardItemDataProvider
|
||||
|
||||
-(id)initForClipboard:(GdkClipboard*)clipboard withContentProvider:(GdkContentProvider*)contentProvider
|
||||
{
|
||||
[super init];
|
||||
g_set_object (&self->_clipboard, clipboard);
|
||||
g_set_object (&self->_contentProvider, contentProvider);
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id)initForDrag:(GdkDrag*)drag withContentProvider:(GdkContentProvider*)contentProvider
|
||||
{
|
||||
[super init];
|
||||
g_set_object (&self->_drag, drag);
|
||||
g_set_object (&self->_contentProvider, contentProvider);
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
g_clear_object (&self->_contentProvider);
|
||||
g_clear_object (&self->_clipboard);
|
||||
g_clear_object (&self->_drag);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(NSArray<NSPasteboardType> *)types
|
||||
{
|
||||
NSMutableArray *ret = [[NSMutableArray alloc] init];
|
||||
GdkContentFormats *serializable;
|
||||
const char * const *mime_types;
|
||||
gsize n_mime_types;
|
||||
|
||||
serializable = gdk_content_provider_ref_storable_formats (self->_contentProvider);
|
||||
serializable = gdk_content_formats_union_serialize_mime_types (serializable);
|
||||
mime_types = gdk_content_formats_get_mime_types (serializable, &n_mime_types);
|
||||
|
||||
for (gsize i = 0; i < n_mime_types; i++)
|
||||
{
|
||||
const char *mime_type = mime_types[i];
|
||||
NSPasteboardType type;
|
||||
NSPasteboardType alternate = nil;
|
||||
|
||||
if ((type = _gdk_macos_pasteboard_to_ns_type (mime_type, &alternate)))
|
||||
{
|
||||
[ret addObject:type];
|
||||
if (alternate)
|
||||
[ret addObject:alternate];
|
||||
}
|
||||
}
|
||||
|
||||
gdk_content_formats_unref (serializable);
|
||||
|
||||
/* Default to an url type (think gobject://internal)
|
||||
* to support internal, GType-based DnD.
|
||||
*/
|
||||
if (n_mime_types == 0)
|
||||
{
|
||||
GdkContentFormats *formats;
|
||||
gsize n_gtypes;
|
||||
|
||||
formats = gdk_content_provider_ref_formats (self->_contentProvider);
|
||||
gdk_content_formats_get_gtypes (formats, &n_gtypes);
|
||||
|
||||
if (n_gtypes)
|
||||
[ret addObject:NSPasteboardTypeURL];
|
||||
|
||||
gdk_content_formats_unref (formats);
|
||||
}
|
||||
|
||||
return g_steal_pointer (&ret);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GMemoryOutputStream *stream;
|
||||
NSPasteboardItem *item;
|
||||
NSPasteboardType type;
|
||||
GMainContext *main_context;
|
||||
guint done : 1;
|
||||
} WriteRequest;
|
||||
|
||||
static void
|
||||
write_request_free (WriteRequest *wr)
|
||||
{
|
||||
g_clear_pointer (&wr->main_context, g_main_context_unref);
|
||||
g_clear_object (&wr->stream);
|
||||
[wr->item release];
|
||||
g_slice_free (WriteRequest, wr);
|
||||
}
|
||||
|
||||
static void
|
||||
on_data_ready_cb (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GDK_BEGIN_MACOS_ALLOC_POOL;
|
||||
|
||||
WriteRequest *wr = user_data;
|
||||
GError *error = NULL;
|
||||
NSData *data = nil;
|
||||
gboolean ret;
|
||||
|
||||
g_assert (G_IS_OBJECT (object));
|
||||
g_assert (GDK_IS_CLIPBOARD (object) || GDK_IS_DRAG (object));
|
||||
g_assert (G_IS_ASYNC_RESULT (result));
|
||||
g_assert (wr != NULL);
|
||||
g_assert (G_IS_MEMORY_OUTPUT_STREAM (wr->stream));
|
||||
g_assert ([wr->item isKindOfClass:[NSPasteboardItem class]]);
|
||||
|
||||
if (GDK_IS_CLIPBOARD (object))
|
||||
ret = gdk_clipboard_write_finish (GDK_CLIPBOARD (object), result, &error);
|
||||
else if (GDK_IS_DRAG (object))
|
||||
ret = gdk_drag_write_finish (GDK_DRAG (object), result, &error);
|
||||
else
|
||||
g_return_if_reached ();
|
||||
|
||||
if (ret)
|
||||
{
|
||||
gsize size;
|
||||
gpointer bytes;
|
||||
|
||||
g_output_stream_close (G_OUTPUT_STREAM (wr->stream), NULL, NULL);
|
||||
|
||||
size = g_memory_output_stream_get_data_size (wr->stream);
|
||||
bytes = g_memory_output_stream_steal_data (wr->stream);
|
||||
data = [[NSData alloc] initWithBytesNoCopy:bytes
|
||||
length:size
|
||||
deallocator:^(void *alloc, NSUInteger length) { g_free (alloc); }];
|
||||
}
|
||||
else
|
||||
{
|
||||
g_warning ("Failed to serialize pasteboard contents: %s",
|
||||
error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
[wr->item setData:data forType:wr->type];
|
||||
|
||||
wr->done = TRUE;
|
||||
|
||||
GDK_END_MACOS_ALLOC_POOL;
|
||||
}
|
||||
|
||||
-(void)pasteboard:(NSPasteboard *)pasteboard item:(NSPasteboardItem *)item provideDataForType:(NSPasteboardType)type
|
||||
{
|
||||
const char *mime_type = _gdk_macos_pasteboard_from_ns_type (type);
|
||||
GMainContext *main_context = g_main_context_default ();
|
||||
WriteRequest *wr;
|
||||
|
||||
if (self->_contentProvider == NULL || mime_type == NULL)
|
||||
{
|
||||
[item setData:[NSData data] forType:type];
|
||||
return;
|
||||
}
|
||||
|
||||
wr = g_slice_new0 (WriteRequest);
|
||||
wr->item = [item retain];
|
||||
wr->stream = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new_resizable ());
|
||||
wr->type = type;
|
||||
wr->main_context = g_main_context_ref (main_context);
|
||||
wr->done = FALSE;
|
||||
|
||||
if (GDK_IS_CLIPBOARD (self->_clipboard))
|
||||
gdk_clipboard_write_async (self->_clipboard,
|
||||
mime_type,
|
||||
G_OUTPUT_STREAM (wr->stream),
|
||||
G_PRIORITY_DEFAULT,
|
||||
NULL,
|
||||
on_data_ready_cb,
|
||||
wr);
|
||||
else if (GDK_IS_DRAG (self->_drag))
|
||||
gdk_drag_write_async (self->_drag,
|
||||
mime_type,
|
||||
G_OUTPUT_STREAM (wr->stream),
|
||||
G_PRIORITY_DEFAULT,
|
||||
NULL,
|
||||
on_data_ready_cb,
|
||||
wr);
|
||||
else
|
||||
g_return_if_reached ();
|
||||
|
||||
/* We're forced to provide data synchronously via this API
|
||||
* so we must block on the main loop. Using another main loop
|
||||
* than the default tends to get us locked up here, so that is
|
||||
* what we'll do for now.
|
||||
*/
|
||||
while (!wr->done)
|
||||
g_main_context_iteration (wr->main_context, TRUE);
|
||||
|
||||
write_request_free (wr);
|
||||
}
|
||||
|
||||
-(void)pasteboardFinishedWithDataProvider:(NSPasteboard *)pasteboard
|
||||
{
|
||||
g_clear_object (&self->_clipboard);
|
||||
g_clear_object (&self->_drag);
|
||||
g_clear_object (&self->_contentProvider);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation GdkMacosPasteboardItem
|
||||
|
||||
-(id)initForClipboard:(GdkClipboard*)clipboard withContentProvider:(GdkContentProvider*)contentProvider
|
||||
{
|
||||
GdkMacosPasteboardItemDataProvider *dataProvider;
|
||||
|
||||
dataProvider = [[GdkMacosPasteboardItemDataProvider alloc] initForClipboard:clipboard withContentProvider:contentProvider];
|
||||
|
||||
[super init];
|
||||
g_set_object (&self->_clipboard, clipboard);
|
||||
g_set_object (&self->_contentProvider, contentProvider);
|
||||
[self setDataProvider:dataProvider forTypes:[dataProvider types]];
|
||||
|
||||
[dataProvider release];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id)initForDrag:(GdkDrag*)drag withContentProvider:(GdkContentProvider*)contentProvider
|
||||
{
|
||||
GdkMacosPasteboardItemDataProvider *dataProvider;
|
||||
|
||||
dataProvider = [[GdkMacosPasteboardItemDataProvider alloc] initForDrag:drag withContentProvider:contentProvider];
|
||||
|
||||
[super init];
|
||||
g_set_object (&self->_drag, drag);
|
||||
g_set_object (&self->_contentProvider, contentProvider);
|
||||
[self setDataProvider:dataProvider forTypes:[dataProvider types]];
|
||||
|
||||
[dataProvider release];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
g_clear_object (&self->_contentProvider);
|
||||
g_clear_object (&self->_clipboard);
|
||||
g_clear_object (&self->_drag);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(NSRect)draggingFrame
|
||||
{
|
||||
return self->_draggingFrame;
|
||||
}
|
||||
|
||||
-(void)setDraggingFrame:(NSRect)draggingFrame;
|
||||
{
|
||||
self->_draggingFrame = draggingFrame;
|
||||
}
|
||||
|
||||
-(id)item
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSArray* (^) (void))imageComponentsProvider
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
@@ -446,7 +446,7 @@ gdk_macos_surface_drag_begin (GdkSurface *surface,
|
||||
gdk_drag_get_selected_action (GDK_DRAG (drag)));
|
||||
gdk_drag_set_cursor (GDK_DRAG (drag), cursor);
|
||||
|
||||
if (!_gdk_macos_drag_begin (drag, content, self->window))
|
||||
if (!_gdk_macos_drag_begin (drag))
|
||||
{
|
||||
g_object_unref (drag);
|
||||
return NULL;
|
||||
|
@@ -19,7 +19,6 @@ gdk_macos_sources = files([
|
||||
'gdkmacoseventsource.c',
|
||||
'gdkmacoskeymap.c',
|
||||
'gdkmacosmonitor.c',
|
||||
'gdkmacospasteboard.c',
|
||||
'gdkmacospopupsurface.c',
|
||||
'gdkmacosseat.c',
|
||||
'gdkmacossurface.c',
|
||||
|
@@ -43,7 +43,6 @@ gdk_public_sources = files([
|
||||
'gdkseatdefault.c',
|
||||
'gdksnapshot.c',
|
||||
'gdktexture.c',
|
||||
'gdktexturedownloader.c',
|
||||
'gdkvulkancontext.c',
|
||||
'gdksurface.c',
|
||||
'gdkpopuplayout.c',
|
||||
@@ -96,7 +95,6 @@ gdk_public_headers = files([
|
||||
'gdkseat.h',
|
||||
'gdksnapshot.h',
|
||||
'gdktexture.h',
|
||||
'gdktexturedownloader.h',
|
||||
'gdktypes.h',
|
||||
'gdkvulkancontext.h',
|
||||
'gdksurface.h',
|
||||
|
@@ -87,7 +87,7 @@ gdk_wayland_app_launch_context_get_startup_notify_id (GAppLaunchContext *context
|
||||
xdg_activation_token_v1_commit (token);
|
||||
|
||||
while (app_launch_data.token == NULL)
|
||||
gdk_wayland_display_dispatch_queue (GDK_DISPLAY (display), event_queue);
|
||||
wl_display_dispatch_queue (display->wl_display, event_queue);
|
||||
|
||||
xdg_activation_token_v1_destroy (token);
|
||||
id = app_launch_data.token;
|
||||
|
@@ -2,236 +2,6 @@
|
||||
#define __GDK_DEVICE_WAYLAND_PRIVATE_H__
|
||||
|
||||
#include "gdkwaylanddevice.h"
|
||||
#include "gdkwaylandseat.h"
|
||||
|
||||
#include <gdk/gdkdeviceprivate.h>
|
||||
#include <gdk/gdkkeysprivate.h>
|
||||
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
|
||||
struct _GdkWaylandDevice
|
||||
{
|
||||
GdkDevice parent_instance;
|
||||
};
|
||||
|
||||
struct _GdkWaylandDeviceClass
|
||||
{
|
||||
GdkDeviceClass parent_class;
|
||||
};
|
||||
|
||||
typedef struct _GdkWaylandTouchData GdkWaylandTouchData;
|
||||
typedef struct _GdkWaylandPointerFrameData GdkWaylandPointerFrameData;
|
||||
typedef struct _GdkWaylandPointerData GdkWaylandPointerData;
|
||||
typedef struct _GdkWaylandTabletPadGroupData GdkWaylandTabletPadGroupData;
|
||||
typedef struct _GdkWaylandTabletPadData GdkWaylandTabletPadData;
|
||||
typedef struct _GdkWaylandTabletData GdkWaylandTabletData;
|
||||
typedef struct _GdkWaylandTabletToolData GdkWaylandTabletToolData;
|
||||
|
||||
struct _GdkWaylandTouchData
|
||||
{
|
||||
uint32_t id;
|
||||
double x;
|
||||
double y;
|
||||
GdkSurface *surface;
|
||||
uint32_t touch_down_serial;
|
||||
guint initial_touch : 1;
|
||||
};
|
||||
|
||||
struct _GdkWaylandPointerFrameData
|
||||
{
|
||||
GdkEvent *event;
|
||||
|
||||
/* Specific to the scroll event */
|
||||
double delta_x, delta_y;
|
||||
int32_t value120_x, value120_y;
|
||||
gint8 is_scroll_stop;
|
||||
enum wl_pointer_axis_source source;
|
||||
};
|
||||
|
||||
struct _GdkWaylandPointerData {
|
||||
GdkSurface *focus;
|
||||
|
||||
double surface_x, surface_y;
|
||||
|
||||
GdkModifierType button_modifiers;
|
||||
|
||||
uint32_t time;
|
||||
uint32_t enter_serial;
|
||||
uint32_t press_serial;
|
||||
|
||||
GdkSurface *grab_surface;
|
||||
uint32_t grab_time;
|
||||
|
||||
struct wl_surface *pointer_surface;
|
||||
guint cursor_is_default: 1;
|
||||
GdkCursor *cursor;
|
||||
guint cursor_timeout_id;
|
||||
guint cursor_image_index;
|
||||
guint cursor_image_delay;
|
||||
guint touchpad_event_sequence;
|
||||
|
||||
guint current_output_scale;
|
||||
GSList *pointer_surface_outputs;
|
||||
|
||||
/* Accumulated event data for a pointer frame */
|
||||
GdkWaylandPointerFrameData frame;
|
||||
};
|
||||
|
||||
struct _GdkWaylandTabletPadGroupData
|
||||
{
|
||||
GdkWaylandTabletPadData *pad;
|
||||
struct zwp_tablet_pad_group_v2 *wp_tablet_pad_group;
|
||||
GList *rings;
|
||||
GList *strips;
|
||||
GList *buttons;
|
||||
|
||||
guint mode_switch_serial;
|
||||
guint n_modes;
|
||||
guint current_mode;
|
||||
|
||||
struct {
|
||||
guint source;
|
||||
gboolean is_stop;
|
||||
double value;
|
||||
} axis_tmp_info;
|
||||
};
|
||||
|
||||
struct _GdkWaylandTabletPadData
|
||||
{
|
||||
GdkSeat *seat;
|
||||
struct zwp_tablet_pad_v2 *wp_tablet_pad;
|
||||
GdkDevice *device;
|
||||
|
||||
GdkWaylandTabletData *current_tablet;
|
||||
|
||||
guint enter_serial;
|
||||
uint32_t n_buttons;
|
||||
char *path;
|
||||
|
||||
GList *rings;
|
||||
GList *strips;
|
||||
GList *mode_groups;
|
||||
};
|
||||
|
||||
struct _GdkWaylandTabletToolData
|
||||
{
|
||||
GdkSeat *seat;
|
||||
struct zwp_tablet_tool_v2 *wp_tablet_tool;
|
||||
GdkAxisFlags axes;
|
||||
GdkDeviceToolType type;
|
||||
guint64 hardware_serial;
|
||||
guint64 hardware_id_wacom;
|
||||
|
||||
GdkDeviceTool *tool;
|
||||
GdkWaylandTabletData *current_tablet;
|
||||
};
|
||||
|
||||
struct _GdkWaylandTabletData
|
||||
{
|
||||
struct zwp_tablet_v2 *wp_tablet;
|
||||
char *name;
|
||||
char *path;
|
||||
uint32_t vid;
|
||||
uint32_t pid;
|
||||
|
||||
GdkDevice *logical_device;
|
||||
GdkDevice *stylus_device;
|
||||
GdkSeat *seat;
|
||||
GdkWaylandPointerData pointer_info;
|
||||
|
||||
GList *pads;
|
||||
|
||||
GdkWaylandTabletToolData *current_tool;
|
||||
|
||||
int axis_indices[GDK_AXIS_LAST];
|
||||
double axes[GDK_AXIS_LAST];
|
||||
};
|
||||
|
||||
struct _GdkWaylandSeat
|
||||
{
|
||||
GdkSeat parent_instance;
|
||||
|
||||
guint32 id;
|
||||
struct wl_seat *wl_seat;
|
||||
struct wl_pointer *wl_pointer;
|
||||
struct wl_keyboard *wl_keyboard;
|
||||
struct wl_touch *wl_touch;
|
||||
struct zwp_pointer_gesture_swipe_v1 *wp_pointer_gesture_swipe;
|
||||
struct zwp_pointer_gesture_pinch_v1 *wp_pointer_gesture_pinch;
|
||||
struct zwp_pointer_gesture_hold_v1 *wp_pointer_gesture_hold;
|
||||
struct zwp_tablet_seat_v2 *wp_tablet_seat;
|
||||
|
||||
GdkDisplay *display;
|
||||
|
||||
GdkDevice *logical_pointer;
|
||||
GdkDevice *logical_keyboard;
|
||||
GdkDevice *pointer;
|
||||
GdkDevice *wheel_scrolling;
|
||||
GdkDevice *finger_scrolling;
|
||||
GdkDevice *continuous_scrolling;
|
||||
GdkDevice *keyboard;
|
||||
GdkDevice *logical_touch;
|
||||
GdkDevice *touch;
|
||||
GdkCursor *cursor;
|
||||
GdkKeymap *keymap;
|
||||
|
||||
GHashTable *touches;
|
||||
GList *tablets;
|
||||
GList *tablet_tools;
|
||||
GList *tablet_pads;
|
||||
|
||||
GdkWaylandPointerData pointer_info;
|
||||
GdkWaylandPointerData touch_info;
|
||||
|
||||
GdkModifierType key_modifiers;
|
||||
GdkSurface *keyboard_focus;
|
||||
GdkSurface *grab_surface;
|
||||
uint32_t grab_time;
|
||||
gboolean have_server_repeat;
|
||||
uint32_t server_repeat_rate;
|
||||
uint32_t server_repeat_delay;
|
||||
|
||||
struct wl_data_offer *pending_offer;
|
||||
GdkContentFormatsBuilder *pending_builder;
|
||||
GdkDragAction pending_source_actions;
|
||||
GdkDragAction pending_action;
|
||||
|
||||
struct wl_callback *repeat_callback;
|
||||
guint32 repeat_timer;
|
||||
guint32 repeat_key;
|
||||
guint32 repeat_count;
|
||||
gint64 repeat_deadline;
|
||||
uint32_t keyboard_time;
|
||||
uint32_t keyboard_key_serial;
|
||||
|
||||
GdkClipboard *clipboard;
|
||||
GdkClipboard *primary_clipboard;
|
||||
struct wl_data_device *data_device;
|
||||
GdkDrag *drag;
|
||||
GdkDrop *drop;
|
||||
|
||||
/* Some tracking on gesture events */
|
||||
guint gesture_n_fingers;
|
||||
double gesture_scale;
|
||||
|
||||
GdkCursor *grab_cursor;
|
||||
};
|
||||
|
||||
#define GDK_TYPE_WAYLAND_DEVICE_PAD (gdk_wayland_device_pad_get_type ())
|
||||
GType gdk_wayland_device_pad_get_type (void);
|
||||
|
||||
void gdk_wayland_seat_stop_cursor_animation (GdkWaylandSeat *seat,
|
||||
GdkWaylandPointerData *pointer);
|
||||
|
||||
GdkWaylandPointerData * gdk_wayland_device_get_pointer (GdkWaylandDevice *wayland_device);
|
||||
|
||||
void gdk_wayland_device_set_pointer (GdkWaylandDevice *wayland_device,
|
||||
GdkWaylandPointerData *pointer);
|
||||
|
||||
GdkWaylandTouchData * gdk_wayland_device_get_emulating_touch (GdkWaylandDevice *wayland_device);
|
||||
|
||||
void gdk_wayland_device_set_emulating_touch (GdkWaylandDevice *wayland_device,
|
||||
GdkWaylandTouchData *touch);
|
||||
|
||||
void gdk_wayland_device_query_state (GdkDevice *device,
|
||||
GdkSurface *surface,
|
||||
@@ -244,24 +14,4 @@ void gdk_wayland_device_pad_set_feedback (GdkDevice *device,
|
||||
guint feature_idx,
|
||||
const char *label);
|
||||
|
||||
GdkWaylandTabletPadData * gdk_wayland_seat_find_pad (GdkWaylandSeat *seat,
|
||||
GdkDevice *device);
|
||||
|
||||
GdkWaylandTabletData * gdk_wayland_seat_find_tablet (GdkWaylandSeat *seat,
|
||||
GdkDevice *device);
|
||||
|
||||
GdkWaylandTouchData * gdk_wayland_seat_get_touch (GdkWaylandSeat *seat,
|
||||
uint32_t id);
|
||||
|
||||
void gdk_wayland_device_maybe_emit_grab_crossing (GdkDevice *device,
|
||||
GdkSurface *window,
|
||||
guint32 time);
|
||||
|
||||
GdkSurface * gdk_wayland_device_maybe_emit_ungrab_crossing (GdkDevice *device,
|
||||
guint32 time_);
|
||||
|
||||
gboolean gdk_wayland_device_update_surface_cursor (GdkDevice *device);
|
||||
|
||||
GdkModifierType gdk_wayland_device_get_modifiers (GdkDevice *device);
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,266 +0,0 @@
|
||||
/* GDK - The GIMP Drawing Kit
|
||||
* Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gdkwaylanddevice.h"
|
||||
#include "gdkdevice-wayland-private.h"
|
||||
|
||||
#include "tablet-unstable-v2-client-protocol.h"
|
||||
|
||||
#include <gdk/gdkdevicepadprivate.h>
|
||||
|
||||
typedef struct _GdkWaylandDevicePad GdkWaylandDevicePad;
|
||||
typedef struct _GdkWaylandDevicePadClass GdkWaylandDevicePadClass;
|
||||
|
||||
struct _GdkWaylandDevicePad
|
||||
{
|
||||
GdkWaylandDevice parent_instance;
|
||||
};
|
||||
|
||||
struct _GdkWaylandDevicePadClass
|
||||
{
|
||||
GdkWaylandDeviceClass parent_class;
|
||||
};
|
||||
|
||||
static void gdk_wayland_device_pad_iface_init (GdkDevicePadInterface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GdkWaylandDevicePad, gdk_wayland_device_pad,
|
||||
GDK_TYPE_WAYLAND_DEVICE,
|
||||
G_IMPLEMENT_INTERFACE (GDK_TYPE_DEVICE_PAD,
|
||||
gdk_wayland_device_pad_iface_init))
|
||||
|
||||
static int
|
||||
gdk_wayland_device_pad_get_n_groups (GdkDevicePad *pad)
|
||||
{
|
||||
GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad));
|
||||
GdkWaylandTabletPadData *data;
|
||||
|
||||
data = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat),
|
||||
GDK_DEVICE (pad));
|
||||
#ifdef G_DISABLE_ASSERT
|
||||
if (data == NULL)
|
||||
return 0;
|
||||
#else
|
||||
g_assert (data != NULL);
|
||||
#endif
|
||||
|
||||
return g_list_length (data->mode_groups);
|
||||
}
|
||||
|
||||
static int
|
||||
gdk_wayland_device_pad_get_group_n_modes (GdkDevicePad *pad,
|
||||
int n_group)
|
||||
{
|
||||
GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad));
|
||||
GdkWaylandTabletPadGroupData *group;
|
||||
GdkWaylandTabletPadData *data;
|
||||
|
||||
data = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat),
|
||||
GDK_DEVICE (pad));
|
||||
#ifdef G_DISABLE_ASSERT
|
||||
if (data == NULL)
|
||||
return 0;
|
||||
#else
|
||||
g_assert (data != NULL);
|
||||
#endif
|
||||
|
||||
group = g_list_nth_data (data->mode_groups, n_group);
|
||||
if (!group)
|
||||
return -1;
|
||||
|
||||
return group->n_modes;
|
||||
}
|
||||
|
||||
static int
|
||||
gdk_wayland_device_pad_get_n_features (GdkDevicePad *pad,
|
||||
GdkDevicePadFeature feature)
|
||||
{
|
||||
GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad));
|
||||
GdkWaylandTabletPadData *data;
|
||||
|
||||
data = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat),
|
||||
GDK_DEVICE (pad));
|
||||
g_assert (data != NULL);
|
||||
|
||||
switch (feature)
|
||||
{
|
||||
case GDK_DEVICE_PAD_FEATURE_BUTTON:
|
||||
return data->n_buttons;
|
||||
case GDK_DEVICE_PAD_FEATURE_RING:
|
||||
return g_list_length (data->rings);
|
||||
case GDK_DEVICE_PAD_FEATURE_STRIP:
|
||||
return g_list_length (data->strips);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
gdk_wayland_device_pad_get_feature_group (GdkDevicePad *pad,
|
||||
GdkDevicePadFeature feature,
|
||||
int idx)
|
||||
{
|
||||
GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad));
|
||||
GdkWaylandTabletPadGroupData *group;
|
||||
GdkWaylandTabletPadData *data;
|
||||
GList *l;
|
||||
int i;
|
||||
|
||||
data = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat),
|
||||
GDK_DEVICE (pad));
|
||||
#ifdef G_DISABLE_ASSERT
|
||||
if (data == NULL)
|
||||
return -1;
|
||||
#else
|
||||
g_assert (data != NULL);
|
||||
#endif
|
||||
|
||||
for (l = data->mode_groups, i = 0; l; l = l->next, i++)
|
||||
{
|
||||
group = l->data;
|
||||
|
||||
switch (feature)
|
||||
{
|
||||
case GDK_DEVICE_PAD_FEATURE_BUTTON:
|
||||
if (g_list_find (group->buttons, GINT_TO_POINTER (idx)))
|
||||
return i;
|
||||
break;
|
||||
case GDK_DEVICE_PAD_FEATURE_RING:
|
||||
{
|
||||
gpointer ring;
|
||||
|
||||
ring = g_list_nth_data (data->rings, idx);
|
||||
if (ring && g_list_find (group->rings, ring))
|
||||
return i;
|
||||
break;
|
||||
}
|
||||
case GDK_DEVICE_PAD_FEATURE_STRIP:
|
||||
{
|
||||
gpointer strip;
|
||||
strip = g_list_nth_data (data->strips, idx);
|
||||
if (strip && g_list_find (group->strips, strip))
|
||||
return i;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_wayland_device_pad_iface_init (GdkDevicePadInterface *iface)
|
||||
{
|
||||
iface->get_n_groups = gdk_wayland_device_pad_get_n_groups;
|
||||
iface->get_group_n_modes = gdk_wayland_device_pad_get_group_n_modes;
|
||||
iface->get_n_features = gdk_wayland_device_pad_get_n_features;
|
||||
iface->get_feature_group = gdk_wayland_device_pad_get_feature_group;
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_wayland_device_pad_class_init (GdkWaylandDevicePadClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_wayland_device_pad_init (GdkWaylandDevicePad *pad)
|
||||
{
|
||||
}
|
||||
|
||||
static GdkWaylandTabletPadGroupData *
|
||||
tablet_pad_lookup_button_group (GdkWaylandTabletPadData *pad,
|
||||
uint32_t button)
|
||||
{
|
||||
GdkWaylandTabletPadGroupData *group;
|
||||
GList *l;
|
||||
|
||||
for (l = pad->mode_groups; l; l = l->next)
|
||||
{
|
||||
group = l->data;
|
||||
|
||||
if (g_list_find (group->buttons, GUINT_TO_POINTER (button)))
|
||||
return group;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*<private>
|
||||
* gdk_wayland_device_pad_set_feedback:
|
||||
* @device: (type GdkWaylandDevice): a %GDK_SOURCE_TABLET_PAD device
|
||||
* @feature: Feature to set the feedback label for
|
||||
* @feature_idx: 0-indexed index of the feature to set the feedback label for
|
||||
* @label: Feedback label
|
||||
*
|
||||
* Sets the feedback label for the given feature/index.
|
||||
*
|
||||
* This may be used by the compositor to provide user feedback
|
||||
* of the actions available/performed.
|
||||
*/
|
||||
void
|
||||
gdk_wayland_device_pad_set_feedback (GdkDevice *device,
|
||||
GdkDevicePadFeature feature,
|
||||
guint feature_idx,
|
||||
const char *label)
|
||||
{
|
||||
GdkWaylandTabletPadData *pad;
|
||||
GdkWaylandTabletPadGroupData *group;
|
||||
GdkSeat *seat;
|
||||
|
||||
seat = gdk_device_get_seat (device);
|
||||
pad = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat), device);
|
||||
if (!pad)
|
||||
return;
|
||||
|
||||
if (feature == GDK_DEVICE_PAD_FEATURE_BUTTON)
|
||||
{
|
||||
group = tablet_pad_lookup_button_group (pad, feature_idx);
|
||||
if (!group)
|
||||
return;
|
||||
|
||||
zwp_tablet_pad_v2_set_feedback (pad->wp_tablet_pad, feature_idx, label,
|
||||
group->mode_switch_serial);
|
||||
}
|
||||
else if (feature == GDK_DEVICE_PAD_FEATURE_RING)
|
||||
{
|
||||
struct zwp_tablet_pad_ring_v2 *wp_pad_ring;
|
||||
|
||||
wp_pad_ring = g_list_nth_data (pad->rings, feature_idx);
|
||||
if (!wp_pad_ring)
|
||||
return;
|
||||
|
||||
group = zwp_tablet_pad_ring_v2_get_user_data (wp_pad_ring);
|
||||
zwp_tablet_pad_ring_v2_set_feedback (wp_pad_ring, label,
|
||||
group->mode_switch_serial);
|
||||
|
||||
}
|
||||
else if (feature == GDK_DEVICE_PAD_FEATURE_STRIP)
|
||||
{
|
||||
struct zwp_tablet_pad_strip_v2 *wp_pad_strip;
|
||||
|
||||
wp_pad_strip = g_list_nth_data (pad->strips, feature_idx);
|
||||
if (!wp_pad_strip)
|
||||
return;
|
||||
|
||||
group = zwp_tablet_pad_strip_v2_get_user_data (wp_pad_strip);
|
||||
zwp_tablet_pad_strip_v2_set_feedback (wp_pad_strip, label,
|
||||
group->mode_switch_serial);
|
||||
}
|
||||
}
|
@@ -832,8 +832,6 @@ gdk_wayland_display_get_next_serial (GdkDisplay *display)
|
||||
* if no ID has been defined.
|
||||
*
|
||||
* Returns: (nullable): the startup notification ID for @display
|
||||
*
|
||||
* Deprecated: 4.10.
|
||||
*/
|
||||
const char *
|
||||
gdk_wayland_display_get_startup_notification_id (GdkDisplay *display)
|
||||
@@ -855,8 +853,6 @@ gdk_wayland_display_get_startup_notification_id (GdkDisplay *display)
|
||||
* The startup ID is also what is used to signal that the startup is
|
||||
* complete (for example, when opening a window or when calling
|
||||
* [method@Gdk.Display.notify_startup_complete]).
|
||||
*
|
||||
* Deprecated: 4.10. Use [method@Gdk.Toplevel.set_startup_id]
|
||||
*/
|
||||
void
|
||||
gdk_wayland_display_set_startup_notification_id (GdkDisplay *display,
|
||||
@@ -985,9 +981,7 @@ gdk_wayland_display_class_init (GdkWaylandDisplayClass *class)
|
||||
display_class->queue_events = _gdk_wayland_display_queue_events;
|
||||
display_class->get_app_launch_context = _gdk_wayland_display_get_app_launch_context;
|
||||
display_class->get_next_serial = gdk_wayland_display_get_next_serial;
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
display_class->get_startup_notification_id = gdk_wayland_display_get_startup_notification_id;
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
display_class->notify_startup_complete = gdk_wayland_display_notify_startup_complete;
|
||||
display_class->create_surface = _gdk_wayland_display_create_surface;
|
||||
display_class->get_keymap = _gdk_wayland_display_get_keymap;
|
||||
@@ -2332,7 +2326,6 @@ apply_monitor_change (GdkWaylandMonitor *monitor)
|
||||
monitor->x, monitor->y,
|
||||
monitor->width, monitor->height });
|
||||
gdk_monitor_set_connector (GDK_MONITOR (monitor), monitor->name);
|
||||
gdk_monitor_set_description (GDK_MONITOR (monitor), monitor->description);
|
||||
monitor->wl_output_done = FALSE;
|
||||
monitor->xdg_output_done = FALSE;
|
||||
|
||||
@@ -2389,7 +2382,7 @@ xdg_output_handle_name (void *data,
|
||||
{
|
||||
GdkWaylandMonitor *monitor = (GdkWaylandMonitor *) data;
|
||||
|
||||
GDK_DEBUG (MISC, "handle name xdg-output %d: %s", monitor->id, name);
|
||||
GDK_DEBUG (MISC, "handle name xdg-output %d", monitor->id);
|
||||
|
||||
monitor->name = g_strdup (name);
|
||||
}
|
||||
@@ -2399,11 +2392,8 @@ xdg_output_handle_description (void *data,
|
||||
struct zxdg_output_v1 *xdg_output,
|
||||
const char *description)
|
||||
{
|
||||
GdkWaylandMonitor *monitor = (GdkWaylandMonitor *) data;
|
||||
|
||||
GDK_DEBUG (MISC, "handle description xdg-output %d: %s", monitor->id, description);
|
||||
|
||||
monitor->description = g_strdup (description);
|
||||
GDK_DEBUG (MISC, "handle description xdg-output %d",
|
||||
((GdkWaylandMonitor *)data)->id);
|
||||
}
|
||||
|
||||
static const struct zxdg_output_v1_listener xdg_output_listener = {
|
||||
@@ -2694,17 +2684,3 @@ gdk_wayland_display_query_registry (GdkDisplay *display,
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
gdk_wayland_display_dispatch_queue (GdkDisplay *display,
|
||||
struct wl_event_queue *event_queue)
|
||||
{
|
||||
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
|
||||
|
||||
if (wl_display_dispatch_queue (display_wayland->wl_display, event_queue) == -1)
|
||||
{
|
||||
g_message ("Error %d (%s) dispatching to Wayland display.",
|
||||
errno, g_strerror (errno));
|
||||
_exit (1);
|
||||
}
|
||||
}
|
||||
|
@@ -158,9 +158,6 @@ struct _GdkWaylandDisplayClass
|
||||
|
||||
gboolean gdk_wayland_display_prefers_ssd (GdkDisplay *display);
|
||||
|
||||
void gdk_wayland_display_dispatch_queue (GdkDisplay *display,
|
||||
struct wl_event_queue *event_queue);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GDK_WAYLAND_DISPLAY__ */
|
||||
|
@@ -25,7 +25,6 @@
|
||||
|
||||
#include "gdkdisplay-wayland.h"
|
||||
#include "gdksurface-wayland.h"
|
||||
#include "gdksurface-wayland-private.h"
|
||||
|
||||
#include "gdkwaylanddisplay.h"
|
||||
#include "gdkwaylandglcontext.h"
|
||||
@@ -61,17 +60,10 @@ gdk_wayland_gl_context_end_frame (GdkDrawContext *draw_context,
|
||||
cairo_region_t *painted)
|
||||
{
|
||||
GdkSurface *surface = gdk_draw_context_get_surface (draw_context);
|
||||
GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
|
||||
int dx = impl->pending_buffer_offset_x;
|
||||
int dy = impl->pending_buffer_offset_y;
|
||||
|
||||
gdk_wayland_surface_sync (surface);
|
||||
gdk_wayland_surface_request_frame (surface);
|
||||
|
||||
if (wl_surface_get_version (impl->display_server.wl_surface) >=
|
||||
WL_SURFACE_OFFSET_SINCE_VERSION)
|
||||
wl_surface_offset (impl->display_server.wl_surface, dx, dy);
|
||||
|
||||
GDK_DRAW_CONTEXT_CLASS (gdk_wayland_gl_context_parent_class)->end_frame (draw_context, painted);
|
||||
|
||||
gdk_wayland_surface_notify_committed (surface);
|
||||
|
@@ -46,7 +46,6 @@ gdk_wayland_monitor_finalize (GObject *object)
|
||||
GdkWaylandMonitor *monitor = (GdkWaylandMonitor *)object;
|
||||
|
||||
g_free (monitor->name);
|
||||
g_free (monitor->description);
|
||||
|
||||
g_clear_pointer (&monitor->xdg_output, zxdg_output_v1_destroy);
|
||||
|
||||
|
@@ -38,7 +38,6 @@ struct _GdkWaylandMonitor {
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
char *name;
|
||||
char *description;
|
||||
gboolean wl_output_done;
|
||||
gboolean xdg_output_done;
|
||||
};
|
||||
|
@@ -1334,6 +1334,8 @@ gdk_wayland_surface_present_popup (GdkWaylandPopup *wayland_popup,
|
||||
GdkPopupLayout *layout)
|
||||
{
|
||||
GdkSurface *surface = GDK_SURFACE (wayland_popup);
|
||||
GdkWaylandDisplay *display_wayland =
|
||||
GDK_WAYLAND_DISPLAY (gdk_surface_get_display (surface));
|
||||
GdkWaylandSurface *wayland_surface = GDK_WAYLAND_SURFACE (wayland_popup);
|
||||
|
||||
if (!wayland_surface->mapped)
|
||||
@@ -1386,10 +1388,7 @@ gdk_wayland_surface_present_popup (GdkWaylandPopup *wayland_popup,
|
||||
}
|
||||
|
||||
while (wayland_popup->display_server.xdg_popup && !is_relayout_finished (surface))
|
||||
{
|
||||
gdk_wayland_display_dispatch_queue (surface->display,
|
||||
wayland_surface->event_queue);
|
||||
}
|
||||
wl_display_dispatch_queue (display_wayland->wl_display, wayland_surface->event_queue);
|
||||
|
||||
if (wayland_popup->display_server.xdg_popup)
|
||||
{
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -229,7 +229,7 @@ gdk_wayland_surface_update_size (GdkSurface *surface,
|
||||
|
||||
if (impl->display_server.egl_window)
|
||||
wl_egl_window_resize (impl->display_server.egl_window, width * scale, height * scale, 0, 0);
|
||||
if (impl->display_server.wl_surface && scale_changed)
|
||||
if (impl->display_server.wl_surface)
|
||||
wl_surface_set_buffer_scale (impl->display_server.wl_surface, scale);
|
||||
|
||||
gdk_surface_invalidate_rect (surface, NULL);
|
||||
@@ -579,12 +579,33 @@ gdk_wayland_surface_attach_image (GdkSurface *surface,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_wayland_surface_sync_offset (GdkSurface *surface)
|
||||
{
|
||||
GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
|
||||
|
||||
if (wl_surface_get_version (impl->display_server.wl_surface) <
|
||||
WL_SURFACE_OFFSET_SINCE_VERSION)
|
||||
return;
|
||||
|
||||
if (impl->pending_buffer_offset_x == 0 &&
|
||||
impl->pending_buffer_offset_y == 0)
|
||||
return;
|
||||
|
||||
wl_surface_offset (impl->display_server.wl_surface,
|
||||
impl->pending_buffer_offset_x,
|
||||
impl->pending_buffer_offset_y);
|
||||
impl->pending_buffer_offset_x = 0;
|
||||
impl->pending_buffer_offset_y = 0;
|
||||
}
|
||||
|
||||
void
|
||||
gdk_wayland_surface_sync (GdkSurface *surface)
|
||||
{
|
||||
gdk_wayland_surface_sync_shadow (surface);
|
||||
gdk_wayland_surface_sync_opaque_region (surface);
|
||||
gdk_wayland_surface_sync_input_region (surface);
|
||||
gdk_wayland_surface_sync_offset (surface);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@@ -2119,10 +2119,7 @@ gdk_wayland_toplevel_focus (GdkToplevel *toplevel,
|
||||
xdg_activation_token_v1_commit (token);
|
||||
|
||||
while (startup_id == NULL)
|
||||
{
|
||||
gdk_wayland_display_dispatch_queue (GDK_DISPLAY (display_wayland),
|
||||
event_queue);
|
||||
}
|
||||
wl_display_dispatch_queue (display_wayland->wl_display, event_queue);
|
||||
|
||||
xdg_activation_token_v1_destroy (token);
|
||||
wl_event_queue_destroy (event_queue);
|
||||
|
@@ -53,9 +53,9 @@ GDK_AVAILABLE_IN_ALL
|
||||
void gdk_wayland_display_set_cursor_theme (GdkDisplay *display,
|
||||
const char *name,
|
||||
int size);
|
||||
GDK_DEPRECATED_IN_4_10
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
const char * gdk_wayland_display_get_startup_notification_id (GdkDisplay *display);
|
||||
GDK_DEPRECATED_IN_4_10_FOR(gdk_toplevel_set_startup_id)
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gdk_wayland_display_set_startup_notification_id (GdkDisplay *display,
|
||||
const char *startup_id);
|
||||
|
||||
|
@@ -6,17 +6,15 @@ gdk_wayland_sources = files([
|
||||
'gdkclipboard-wayland.c',
|
||||
'gdkcursor-wayland.c',
|
||||
'gdkdevice-wayland.c',
|
||||
'gdkdevicepad-wayland.c',
|
||||
'gdkdisplay-wayland.c',
|
||||
'gdkdrag-wayland.c',
|
||||
'gdkdragsurface-wayland.c',
|
||||
'gdkdrop-wayland.c',
|
||||
'gdkeventsource.c',
|
||||
'gdkglcontext-wayland.c',
|
||||
'gdkkeymap-wayland.c',
|
||||
'gdkkeys-wayland.c',
|
||||
'gdkmonitor-wayland.c',
|
||||
'gdkprimary-wayland.c',
|
||||
'gdkseat-wayland.c',
|
||||
'gdksurface-wayland.c',
|
||||
'gdktoplevel-wayland.c',
|
||||
'gdkpopup-wayland.c',
|
||||
|
@@ -631,14 +631,6 @@ gdk_win32_gl_context_wgl_clear_current (GdkGLContext *context)
|
||||
return wglMakeCurrent (NULL, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gdk_win32_gl_context_wgl_is_current (GdkGLContext *context)
|
||||
{
|
||||
GdkWin32GLContextWGL *self = GDK_WIN32_GL_CONTEXT_WGL (context);
|
||||
|
||||
return self->wgl_context == wglGetCurrentContext ();
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gdk_win32_gl_context_wgl_make_current (GdkGLContext *context,
|
||||
gboolean surfaceless)
|
||||
@@ -690,7 +682,6 @@ gdk_win32_gl_context_wgl_class_init (GdkWin32GLContextWGLClass *klass)
|
||||
context_class->realize = gdk_win32_gl_context_wgl_realize;
|
||||
context_class->make_current = gdk_win32_gl_context_wgl_make_current;
|
||||
context_class->clear_current = gdk_win32_gl_context_wgl_clear_current;
|
||||
context_class->is_current = gdk_win32_gl_context_wgl_is_current;
|
||||
|
||||
draw_context_class->begin_frame = gdk_win32_gl_context_wgl_begin_frame;
|
||||
draw_context_class->end_frame = gdk_win32_gl_context_wgl_end_frame;
|
||||
|
@@ -740,6 +740,7 @@ GPtrArray *
|
||||
_gdk_win32_display_get_monitor_list (GdkWin32Display *win32_display)
|
||||
{
|
||||
EnumMonitorData data;
|
||||
int i;
|
||||
|
||||
data.display = win32_display;
|
||||
data.monitors = get_monitor_devices (win32_display);
|
||||
|
@@ -2066,10 +2066,19 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
|
||||
xev->detail != XINotifyInferior && xev->mode != XINotifyPassiveUngrab &&
|
||||
GDK_IS_TOPLEVEL (surface))
|
||||
{
|
||||
GList *l;
|
||||
if (gdk_x11_device_xi2_get_device_type ((GdkX11DeviceXI2 *) device) != GDK_X11_DEVICE_TYPE_LOGICAL)
|
||||
_gdk_device_xi2_reset_scroll_valuators (GDK_X11_DEVICE_XI2 (source_device));
|
||||
else
|
||||
{
|
||||
GList *physical_devices, *l;
|
||||
|
||||
for (l = device_manager->devices; l; l = l->next)
|
||||
_gdk_device_xi2_reset_scroll_valuators (GDK_X11_DEVICE_XI2 (l->data));
|
||||
physical_devices = gdk_device_list_physical_devices (source_device);
|
||||
|
||||
for (l = physical_devices; l; l = l->next)
|
||||
_gdk_device_xi2_reset_scroll_valuators (GDK_X11_DEVICE_XI2 (l->data));
|
||||
|
||||
g_list_free (physical_devices);
|
||||
}
|
||||
}
|
||||
|
||||
event = gdk_crossing_event_new (ev->evtype == XI_Enter
|
||||
|
@@ -2074,10 +2074,8 @@ gdk_x11_display_make_default (GdkDisplay *display)
|
||||
display_x11->startup_notification_id = NULL;
|
||||
|
||||
startup_id = gdk_get_startup_notification_id ();
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
if (startup_id)
|
||||
gdk_x11_display_set_startup_notification_id (display, startup_id);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2305,8 +2303,6 @@ gdk_x11_display_get_user_time (GdkDisplay *display)
|
||||
* Gets the startup notification ID for a display.
|
||||
*
|
||||
* Returns: the startup notification ID for @display
|
||||
*
|
||||
* Deprecated: 4.10
|
||||
*/
|
||||
const char *
|
||||
gdk_x11_display_get_startup_notification_id (GdkDisplay *display)
|
||||
@@ -2333,9 +2329,7 @@ gdk_x11_display_get_startup_notification_id (GdkDisplay *display)
|
||||
* The startup ID is also what is used to signal that the startup is
|
||||
* complete (for example, when opening a window or when calling
|
||||
* gdk_display_notify_startup_complete()).
|
||||
*
|
||||
* Deprecated: 4.10: Using [method@Gdk.Toplevel.set_startup_id] is sufficient
|
||||
*/
|
||||
**/
|
||||
void
|
||||
gdk_x11_display_set_startup_notification_id (GdkDisplay *display,
|
||||
const char *startup_id)
|
||||
@@ -3048,9 +3042,7 @@ gdk_x11_display_class_init (GdkX11DisplayClass * class)
|
||||
display_class->get_app_launch_context = _gdk_x11_display_get_app_launch_context;
|
||||
|
||||
display_class->get_next_serial = gdk_x11_display_get_next_serial;
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
display_class->get_startup_notification_id = gdk_x11_display_get_startup_notification_id;
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
display_class->notify_startup_complete = gdk_x11_display_notify_startup_complete;
|
||||
display_class->create_surface = _gdk_x11_display_create_surface;
|
||||
display_class->get_keymap = gdk_x11_display_get_keymap;
|
||||
|
@@ -1912,7 +1912,7 @@ drag_grab (GdkDrag *drag)
|
||||
root = GDK_DISPLAY_XROOTWIN (display);
|
||||
seat = gdk_device_get_seat (gdk_drag_get_device (drag));
|
||||
|
||||
capabilities = GDK_SEAT_CAPABILITY_ALL_POINTING | GDK_SEAT_CAPABILITY_KEYBOARD;
|
||||
capabilities = GDK_SEAT_CAPABILITY_ALL_POINTING;
|
||||
|
||||
cursor = gdk_drag_get_cursor (drag, x11_drag->current_action);
|
||||
g_set_object (&x11_drag->cursor, cursor);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user