Compare commits

...

763 Commits

Author SHA1 Message Date
Matthias Clasen
7b68ef7669 widget-factory: Precompile the ui file
It doesn't make a huge amount of difference, unfortunately.
2021-09-19 20:19:34 -04:00
Matthias Clasen
11b9b1759a buildertool: Add a compile command
This converts the ui file into our internal, precompiled,
format. The widget-factory.ui file shrinks from 200k to 45k.
But sadly, the loading time only shrinks from 240ms to 235.
2021-09-19 20:19:34 -04:00
Emin Tufan Çetin
6474c7af35 Update Turkish translation 2021-09-19 17:22:22 +00:00
Emin Tufan Çetin
145a16ff81 Update Turkish translation 2021-09-19 17:18:57 +00:00
Matthias Clasen
f079d75d1f Merge branch 'resource-cleanup' into 'master'
Clean up gesture icons

See merge request GNOME/gtk!3978
2021-09-19 12:53:59 +00:00
Matthias Clasen
e1facc548a resources: Treat svgs as xml
They can have their whitespace removed just the same.
2021-09-19 08:27:08 -04:00
Matthias Clasen
87e4a542eb Clean up gesture icons
These had duplicate drawing in them, and were
saved with all the extra Inkscape data.
2021-09-19 08:27:08 -04:00
Matthias Clasen
56e6a51ac0 Merge branch 'delayed-loading' into 'master'
gtk-demo: Cosmetics

See merge request GNOME/gtk!3975
2021-09-18 23:02:00 +00:00
Matthias Clasen
da115ad075 Use GtkLoader for image loading
This avoids blocking on image loading while
we have better things to do.
2021-09-18 17:35:00 -04:00
Matthias Clasen
4a89cfe2c9 Add delayed loading for textures
Add a private GdkPaintable implementation that
loads a texture in a thread, and does not show
anything until the texture is loaded. This avoid
blocking on image loading in the main thread.
2021-09-18 17:35:00 -04:00
Matthias Clasen
c9135546b6 loaders: Add profiler marks
These are potentially expensive calls, we
should make sure they show up in profiles.
2021-09-18 17:35:00 -04:00
Jordi Mas
a94e438a29 Update Catalan translation 2021-09-18 21:15:31 +02:00
Matthias Clasen
164443a99a builder: Cosmetics 2021-09-18 14:14:55 -04:00
Matthias Clasen
d88c4d122d gtk-demo: Cosmetics
Tweak the color of the outlines in the font rendering
demo.
2021-09-18 11:08:15 -04:00
Matthias Clasen
d66bc501a4 Merge branch 'wip/baedert/for-master' into 'master'
label: Remove redundant store

Closes #4196

See merge request GNOME/gtk!3891
2021-09-18 15:04:09 +00:00
Timm Bäder
1c2c356ed4 widget factory: Scale down jpeg images 2021-09-18 16:48:48 +02:00
Piotr Drąg
1fae91d123 Update POTFILES.in 2021-09-18 13:12:42 +02:00
Timm Bäder
24415a6ffb cssimageurl: Explicitly check for local_error != NULL
This should always be the case since gdk_texture_new_from_file should
always set the error when it returns NULL, but make it explicit anyway.
2021-09-18 13:08:46 +02:00
Timm Bäder
ae08aa3622 constraintsolver: Remove a dead assignment 2021-09-18 12:53:41 +02:00
Timm Bäder
c24b7877a0 gdktiff: Use guint32 instead of int32
The latter seems to be deprecated.
2021-09-18 09:00:16 +02:00
Matthias Clasen
7b22e37371 Merge branch 'transform-work' into 'master'
transform: Add sections

See merge request GNOME/gtk!3974
2021-09-18 06:35:08 +00:00
Timm Bäder
c2ab1f172d window: Fix mnemonics-visible getter+setter annotations 2021-09-18 08:29:18 +02:00
Timm Bäder
136a3f6e5a stackswitcher: Expand child buttons
Fixes #4196
2021-09-18 08:29:18 +02:00
Timm Bäder
2bc82da34d inspector: Cache if we have ever constructed a window
Silly optimization to get rid of

gtk_main_do_event
  gtk_inspector_handle_event
    gtk_inspector_window_get_for_display
      g_object_get_data

showing up in profiles even though it's useless since we've never even
created any inspector window in the first place.
2021-09-18 08:29:18 +02:00
Matthias Clasen
41b810da7f Add gsk_transform_to_2d_components
This function decomposes a general 2D transform
into skew, scale, rotation and translation.

Tests included.
2021-09-18 02:06:51 -04:00
Matthias Clasen
155e0f3dfb Merge branch 'gbsneto/fix-filechooserwidget-choices' into 'master'
File chooser choice fixes

See merge request GNOME/gtk!3973
2021-09-18 03:59:52 +00:00
Georges Basile Stavracas Neto
02bb23486f filechooserwidget: Return an id in get_choice()
gtk_file_chooser_widget_get_choice() is supposed to return the option
id of the choice, but it currently is returning the option label.

Return the option id instead.
2021-09-18 00:22:05 -03:00
Georges Basile Stavracas Neto
bc0d9488ee filechooserwidget: Match choice id from "options"
When choices are added to the file chooser widget, the options of
that choice are stored object data under the "options" key. However,
gtk_file_chooser_widget_set_choice() was checking for "choices".

Retrieve the options from the "options" key stored data object data.
2021-09-18 00:20:42 -03:00
Matthias Clasen
5742483422 Add more transform tests
Test gsk_transform_to_2d.
2021-09-17 22:37:08 -04:00
Matthias Clasen
7f2cb1138a Merge branch 'static-analysis-fixes' into 'master'
label: Remove a dead assignment

See merge request GNOME/gtk!3972
2021-09-18 02:22:21 +00:00
Matthias Clasen
1289e68931 gsk: Add skew transforms
Add gsk_transform_skew() to make our transform
api more complete wrt to what you would expect
for a graphics api.
2021-09-17 22:07:26 -04:00
Matthias Clasen
9e6adaa913 transform: Add sections
This makes the code easier to navigate (for me).
2021-09-17 22:07:26 -04:00
Matthias Clasen
9cfce67d0f textview: Remove a dead store
Pointed out by clang.
2021-09-17 22:06:21 -04:00
Matthias Clasen
295d406207 listitemmanager: Add a few assertions
This might help poor static analyzers.
2021-09-17 22:06:21 -04:00
Matthias Clasen
ece5fd7db5 Merge branch 'more-glyph-drawing-fixes' into 'master'
ngl: Use exact device scales for glyphs

See merge request GNOME/gtk!3971
2021-09-18 00:26:14 +00:00
Matthias Clasen
c4e558da46 imcontextsimple: Rewrite a function slightly
This hopefully avoids upsetting static analyis.
2021-09-17 20:02:12 -04:00
Matthias Clasen
be1a60d5d0 label: Remove a dead assignment
It may have quieted gcc at some point, but
it upsets clang nowadays. Remove it.
2021-09-17 19:54:16 -04:00
Matthias Clasen
a1adaac69b Merge branch 'glyph-clipping-fixes' into 'master'
gtk-demo: Improve ink extents rendering

See merge request GNOME/gtk!3969
2021-09-17 23:31:41 +00:00
Matthias Clasen
7e4b2b971f Revert "gsk: Stop enlarging text bounding boxes"
This reverts commit 87af45403a.

I've found that this change is needed to ensure that the
bounding boxes of text nodes encompass all the glyphd drawing.
Without it, we overdraw the widget boundaries and cut off
glyphs.
2021-09-17 19:11:06 -04:00
Matthias Clasen
c6cacd2b2d ngl: Use exact device scales for glyphs
We are rendering the glyphs on a larger surface,
and we should avoid introducing unnecessary
rounding errors here. Also, I've found that
we always need to enlarge the surface by one
pixels in each direction to avoid cutting off
the tops of large glyphs.
2021-09-17 19:07:55 -04:00
Matthias Clasen
2c8e55605b gtk-demo: Improve ink extents rendering
Show the pixel-aligned ink rectangle, so we can
see that it includes all the pixels that are inked.
2021-09-17 16:29:30 -04:00
Matthias Clasen
06db477847 gtk-demo: Fix non-circular buttons 2021-09-17 15:24:26 -04:00
Matthias Clasen
e9cf8c6cc7 Merge branch 'glyph-clipping-fixes' into 'master'
gsk: Stop enlarging text bounding boxes

See merge request GNOME/gtk!3968
2021-09-17 18:35:41 +00:00
Matthias Clasen
aad6b2d279 Merge branch 'wip/otte/for-master' into 'master'
icontheme: Fix variable mixup leading to crashes

Closes #4269

See merge request GNOME/gtk!3967
2021-09-17 18:06:30 +00:00
Benjamin Otte
cf3830704b icontheme: Fix variable mixup leading to crashes
Note: Don't have 2 variables named "icon" and "gicon", you will screw
them up.

reftests included.

Fixes #4269
2021-09-17 17:41:13 +00:00
Matthias Clasen
d962360fa0 Fix glyph cache entry sizing
The subpixel-positioned glyph extends on both sides.
2021-09-17 13:38:29 -04:00
Matthias Clasen
76d31ff04b Merge branch 'menu_button_a11y_improvements' into 'master'
Set correct accessible relations for GtkMenuButton

Closes #4254

See merge request GNOME/gtk!3950
2021-09-17 16:51:52 +00:00
Matthias Clasen
87af45403a gsk: Stop enlarging text bounding boxes
This should not be necessary and only serves
to make the actual bugs harder to find.
2021-09-17 12:37:36 -04:00
Emmanuele Bassi
15ffd49efb Apply 4 suggestion(s) to 1 file(s) 2021-09-17 16:26:00 +00:00
Matthias Clasen
37a54eb9fc Merge branch 'matthiasc/for-master' into 'master'
gsk: Add a test for transform_bounds

See merge request GNOME/gtk!3966
2021-09-17 16:22:04 +00:00
Matthias Clasen
63647cace0 testsuite: Run the clipboard test in isolation
We can't have other test pop up windows, and possibly
stealing focus and preventing us from getting data
offers. So, run the clipboard test in isolation.
2021-09-17 11:38:28 -04:00
Matthias Clasen
bef54a382d transform: Improve docs
Add an example for reconstructing transforms.
2021-09-17 10:28:49 -04:00
Matthias Clasen
6a60214e8c gsk: Handle 2D transforms better
For 2D transforms, we can read the scale
factors more directly off the matrix.

This should eventually be moved out into a
function to decompose a 2D transform into
scale + rotation + skew + translation.
2021-09-17 10:28:49 -04:00
Matthias Clasen
27d662f1aa node editor: Preserve aspect ratio
We don't want to distort our rendering.
Tell the paintable to keep the aspect
ratio.
2021-09-17 10:28:49 -04:00
Matthias Clasen
52a8492887 rendernodepaintable: Provide accurate aspect ratio
Since we report width and height as integers, the
default implementation of this introduces rounding
errors. This shows up in the node-editor, as having
uneven scale factors like sx=1.0 and sy=1.0035.
Text nodes don't handle uneven scales like that well
and overdraw.
2021-09-17 10:28:49 -04:00
Lukáš Tyrychtr
ba5d010e39 Delete unneccessary comment and make other more descriptive 2021-09-17 15:11:26 +02:00
Matthias Clasen
8c34dd58c0 gsk: Add a test for transform_bounds 2021-09-17 07:43:07 -04:00
Matthias Clasen
0cce92ab19 Merge branch 'fix-typo' into 'master'
gtkcolorbutton: Fix documentation

See merge request GNOME/gtk!3965
2021-09-17 10:52:59 +00:00
James Westman
f95c21b67c gtkcolorbutton: Fix documentation 2021-09-16 23:53:42 -05:00
Benjamin Otte
1d41dc716e Merge branch 'image-loading' into 'master'
Image loaders

See merge request GNOME/gtk!3939
2021-09-17 03:13:38 +00:00
Benjamin Otte
3914ecbd0f gtk-demo: Use textures in listbox example 2021-09-17 04:31:46 +02:00
Benjamin Otte
0428d8ccd6 examples: Use textures over pixbufs 2021-09-17 04:31:46 +02:00
Benjamin Otte
37a7c6780a icontheme: Implement gtk_icon_theme_lookup_by_gicon() for textures
More feature parity.

Before this, it would have worked just as well - just going via a PNG
bytes step inbetween.
2021-09-17 04:31:46 +02:00
Benjamin Otte
1b85b5597b texture: Implement GIcon and GLoadableIcon
This is mainly for feature parity with GdkPixbuf. And it doesn't hurt
anyone (I hope).
2021-09-17 04:31:46 +02:00
Benjamin Otte
fae32846c7 texture: Refactor gdk_texture_new_from_bytes()
1. Split into a real loader and a fake one

2. Only try the fake one if the real one doesn't support the file.
2021-09-17 04:31:46 +02:00
Benjamin Otte
b271a94f92 texture: Rework error enum
1. Change INSUFFICIENT_MEMORY to TOO_LARGE
   GTK crashes on insufficient memory, we don't emit GErrors.

2. Split UNSUPPORTED into UNSUPPORTED_CONTENT and UNSUPPORTED_FORMAT
   So we know if you need to find an RPM with a loader or curse and
   the weird file.

3. Translate error messages, they are meant for end users.
2021-09-17 03:25:35 +02:00
Benjamin Otte
e58f70d7bb pixbufutils: Don't hardcode formats
Just let the loaders figure out the file format themselves.
2021-09-17 02:34:15 +02:00
Benjamin Otte
4fcf54757f icontheme: Insist that people provide proper values
Seriously...
2021-09-17 02:29:59 +02:00
Benjamin Otte
b5da07f0e1 icontheme: Use textures more
We were going via GLoadablieIcon/GInputStream for everything previously
and we have no API for that with GdkTexture.

With this commit, gdk-pixbuf isn't used anymore when starting
widget-factory for anything but SVG.
2021-09-17 02:12:07 +02:00
Benjamin Otte
a85f4ec6c2 icontheme: Load textures directly when possible
This doesn't fix the codepaths for SVG (both for recoloring and
resizing) and doesn't handle streams yet.
2021-09-17 02:02:51 +02:00
Matthias Clasen
b226478e8b Support 16bit formats in the png loader
When loading, convert all >8-bit data to
GDK_MEMORY_R16G16B16A16_PREMULTIPLIED.

When saving, save all 8-bit formats as 8-bit RGBA,
and save all >8-bt formats as 16-bit RGBA.
2021-09-17 02:02:51 +02:00
Matthias Clasen
14280b5f5b contentdeserializer: Use our on jpeg loader 2021-09-17 02:02:51 +02:00
Matthias Clasen
e720f9d35d Add code to save jpegs 2021-09-17 02:02:51 +02:00
Matthias Clasen
fecb31b706 builder: Stop using pixbufutils
We can just use gdk_pixbuf_new_from_resource here.
2021-09-17 02:02:51 +02:00
Matthias Clasen
729ad8e64a cssimageurl: Just create a texture directly
We don't need to use the pixbufutils api here.
2021-09-17 02:02:51 +02:00
Matthias Clasen
dcd873a6d8 builder: create textures without pixbufs
Load textures using the GdkTexture apis, without
going through a pixbuf first.
2021-09-17 02:02:51 +02:00
Benjamin Otte
679c93e843 texture: Add private can_load() function
... and use it to load textures in gtk_picture_set_from_file().
2021-09-17 00:25:22 +02:00
Benjamin Otte
2d3de8608c texture: Split out type detection
This way, the code using it becomes clearer and we can use it in
multiple places without accidentally doing it wrong (hint: see next
commit).
2021-09-17 00:25:22 +02:00
Benjamin Otte
100b0bf7d9 texture: Remove declaration for nonexisting function 2021-09-17 00:25:22 +02:00
Matthias Clasen
f2ca9ebbd7 texture: Avoid pixbufs when loading resources
We can just use our own loaders here now.
2021-09-17 00:25:22 +02:00
Benjamin Otte
577bf104c0 testsuite: Add png and tiff methods
We encode the texture to a PNG or TIFF and then decode
it again, in various ways.
2021-09-17 00:25:22 +02:00
Benjamin Otte
b1bb7c3258 texture: Add gdk_texture_save_to_tiff_bytes() 2021-09-17 00:25:22 +02:00
Matthias Clasen
c77b5c46a3 rendernodeparser: Avoid gdk_texture_new_for_pixbuf
We can just use gdk_texture_new_from_bytes here now.

Update affected test output.
2021-09-17 00:25:22 +02:00
Matthias Clasen
5b82cf1145 rendernodeparser: Use gdk_texture_save_to_png_bytes
Avoid cairo, and use our own api for saving png data.

Update affected test output.
2021-09-17 00:25:22 +02:00
Matthias Clasen
95a0c93839 Add contentserializer tests for textures 2021-09-17 00:25:22 +02:00
Matthias Clasen
d27bc74481 Use our own loaders for content (de)serialization
Use our own loader to (de)serialiaze textures
to and from png and tiff.

We still fall back to gdk-pixbuf for handling all
the other image formats, and for pixbufs.
2021-09-17 00:25:22 +02:00
Matthias Clasen
e30b4c61cb Add tests for the jpeg loader 2021-09-17 00:25:22 +02:00
Matthias Clasen
daf29e174f Load jpegs without gdk-pixbuf
Use our own loader for jpeg files.
2021-09-17 00:25:22 +02:00
Matthias Clasen
729ba8111a Add code to load jpegs
This lets us avoid gdk-pixbuf for loading
textures from the common image formats.

As a consequence, we are now linking against libjpeg.
2021-09-17 00:25:22 +02:00
Matthias Clasen
d30a029689 Add gdk_texture_save_to_tiff
This is a companion to gdk_texture_save_to_png, using
the tiff format, which will let us avoid lossy conversion
of HDR data, since we can store floating point data.
2021-09-17 00:25:22 +02:00
Matthias Clasen
945c2531ac Add tests for the tiff loader 2021-09-17 00:25:22 +02:00
Matthias Clasen
f925e12e1d Load tiffs without gdk-pixbuf
This will let us load floating point data, in
the future.
2021-09-17 00:25:22 +02:00
Matthias Clasen
a03594df52 Add code to load and save tiff files
Add support for the tiff format, which is flexible
enough to handle all our memory texture formats
without loss.

As a consequence, we are now linking against libtiff.
2021-09-17 00:25:22 +02:00
Matthias Clasen
d7c8f92733 Add gdk_texture_save_to_png_bytes
Just expose what we already have available
internally, so e.g. tests can use it without
static linking.
2021-09-17 00:25:22 +02:00
Matthias Clasen
d6ce65f81c Add tests for the png loader 2021-09-17 00:25:22 +02:00
Matthias Clasen
7949aaabb7 Save pngs without cairo
Use our own loader for pngs, which will allow
us to save e.g. 16-bit data in the future.
2021-09-17 00:25:22 +02:00
Matthias Clasen
a71877bf99 Load pngs without gdk-pixbuf
Use our own loader for pngs, which will allow
us to get e.g. 16-bit data in the future.
2021-09-17 00:25:22 +02:00
Matthias Clasen
f51f7f85eb Add code to load and save pngs
Using libpng instead of the lowest-common-denominator
gdk-pixbuf loader. This will allow us to load >8bit data,
and apply gamma and color correction in the future.
For now, this still just provides RGBA8 data.

As a consequence, we are now linking against libpng.
2021-09-17 00:25:22 +02:00
Matthias Clasen
66031fd00b texture: Add error enum 2021-09-17 00:25:22 +02:00
Benjamin Otte
698b3542a1 Merge branch 'modern-testsuite' into 'master'
testsuite: modernize image handling

Closes #4261

See merge request GNOME/gtk!3955
2021-09-16 22:22:56 +00:00
Benjamin Otte
83ea623775 reftests: Use the default (aka NGL) renderer
All tests pass with the renderer now, so we can remove useof the
fallback.
2021-09-16 23:59:37 +02:00
Benjamin Otte
345faa7250 reftests: XFAIL border-half-pixel test
the GL renderer can't deal with non-integers
2021-09-16 23:59:37 +02:00
Benjamin Otte
08df891070 reftests: Use colors without rounding errors
Color values must be divisible by 15 to be convertible into U8 and U16
values with the same result. 0x80 is not one of these values, so switch
it to 0x99.
2021-09-16 23:59:37 +02:00
Benjamin Otte
56b31c3923 rendernodeparser: Handle is_color attribute for glyphs 2021-09-16 23:59:37 +02:00
Matthias Clasen
93323be22a ngl: Avoid offscreens in more cases
We avoid an offscreen if we know the child node
can 'handle' the transform. Shadow nodes can if their
child node does - either the child node is a text node
in which case the shortcuts we take for shadow nodes
will work fine with the transform (we just render the
text node offset), or the child is not a text node,
in which case we render the shadow to an offscreen
anyway.

This change makes the label-shadows reftest pass with
the GL renderer, not by fixing the issue but by avoiding
it.
2021-09-16 23:59:37 +02:00
Matthias Clasen
9e14de2534 ngl: Improve shortcuts for shadow nodes
For shadow nodes, we try pretty hard to avoid
rendering shadows, and and we have a shortcut
that just renders text offset, but we can try
harder to do nothing - if the text is offset
by zero, we don't need to draw it at all.
2021-09-16 23:59:37 +02:00
Benjamin Otte
62954a0338 ngl Fix bottom-right border render failure
The wrong index was used for offsetting the bottom border rect.

Test included.
2021-09-16 23:59:37 +02:00
Benjamin Otte
7cf5e5546b testsuite: Switch color from khaki to yellow
llvmpipe doesn't loike compositing semitransparent khaki onto solid
khaki without rounding errors.
2021-09-16 23:59:37 +02:00
Benjamin Otte
58f66ebd07 reftests: Make image-compare use textures
All image comparisons are done on textures now.
2021-09-16 23:59:37 +02:00
Benjamin Otte
47330598fb reftests: Use 0.6 instead of 0.5 for alpha
See previous commit about rounding
2021-09-16 23:59:37 +02:00
Benjamin Otte
90ed7b92b2 reftests: Use 0.6 alpha, not 0.5
0.5 leads to some GL renderers computing 0.5 * 0xFF as 0x7F and
others 0x80, while 0.6 * 0xFF (255 is divisible by 5) is always 0x99.
2021-09-16 23:59:37 +02:00
Benjamin Otte
625b5ce91a testsuite: Port compare_render() to use textures 2021-09-16 23:59:37 +02:00
Benjamin Otte
c84d5b1f7f tests: Update rendernode test to use textures 2021-09-16 23:59:37 +02:00
Benjamin Otte
46bb160923 testuite: Add opacity-overdraw test
Tests that overdrawing of content inside an opacity node happens before
the opacity is applied.

This is broken in the GL renderer and causes the opacity.ui reftest to
fail.
2021-09-16 23:59:37 +02:00
Matthias Clasen
390a0b2f2a ngl: Fix opacity handling
We need to use an offscreen whenever there is overlapping
children somewhere in the tree below, just checking the
direct child of the opacity node is not enough.

Fixes: #4261
2021-09-16 23:59:37 +02:00
Benjamin Otte
0dfab46c15 reftests: Use GdkTexture instead of cairo_surface_t
This also switches the rendering code from using gsk_render_node_draw()
to gsk_renderer_render_texture().

Some tests are broken with the GL renderer, so this patch forces the
Cairo renderer until they get fixed.
2021-09-16 23:59:37 +02:00
Benjamin Otte
3a8ec683d3 reftests: Make diff pixels always opaque
We had pixels that did not differ in alpha and we then set 0 alpha
difference hich made the pixel invisible. Oops.
2021-09-16 23:59:37 +02:00
Benjamin Otte
de53b0c7a3 testsuite: remove box-order test
The test used to test that GtkBox ordered it's children left-to-right in
CSS, no matter the text direction or pack-type.

But there is neither a pack-type anymore nor does GTK4 do that.

So that test has been broken for yers, it just didn't render anything
wrong.
2021-09-16 23:59:37 +02:00
Benjamin Otte
75dfb4d63b API: Add gdk_texture_new_from_filename()
There are quite a few places where we can make use of it, in particular
in the testsuite and icontheme.
2021-09-16 23:59:37 +02:00
Benjamin Otte
64acaf99fb testsuite: Fix race in texture-threads test
Threads are evil, yo.
2021-09-16 23:59:37 +02:00
Benjamin Otte
551f76ea69 gltexture: Fallback in download_float()
GLES only allows downloading float if the texture matches specific
criteria and I'm too lazy to determine them, so always fall back.

And the custom stride fallback code isn't necessary, because falling
back does exactly that step already.
2021-09-16 23:59:37 +02:00
Benjamin Otte
a4f3fbbda1 gltexture: Fix download() for GLES
GLES can't do glGetTexImage(), so implement a version that does
glReadPixels() on GLES.
2021-09-16 23:59:37 +02:00
Benjamin Otte
b6d3561f4a testsuite: Be more verbose in texture-threads test
The test randomly fails on CI, so try to be more helpful in debugging
them.
2021-09-16 23:59:37 +02:00
Matthias Clasen
01944d57b7 Merge branch 'master' into 'master'
Do not require wayland-protocols as dependency in the .pc files

See merge request GNOME/gtk!3960
2021-09-16 18:32:23 +00:00
muradm
c9aec9b5a2 Do not require wayland-protocols as dependency in the .pc file
Basically, I was building some packages on Guix. I figured out that
wayland-protocols was listed among propagated-inputs for gtk+ package
(gtk-3-24). propagated-inputs holds a list of runtime dependencies,
that should be available to any other package that depends on gtk+.
While discussing we clarified that wayland-protocols is not runtime
dependency. So I moved it to native-inputs of gtk+ package, which
means that, this dependency will be available only to gtk+ package and
only at build time. Once moved, building of other applications that
depening on gtk+ started to fail.

Investigation showed that, all .pc (pkg-config) files prepared by gtk+
package, was including:

Requires.private: ... wayland-protocols ...

Since it becomes requirement, other applications was failing with
missing dependency wayland-protocols of dependency gtk+, for instance:

-- Checking for module 'gtk+-3.0'
--   Package 'wayland-protocols', required by 'gdk-3.0', not found

While actually wayland-protocols is not even a build time dependency
of application that depends on gtk+. Advertisement of such
requirement, is a bit misleading, because one does not need it at
runtime, especially applications based on gtk.
2021-09-16 20:31:30 +03:00
Matthias Clasen
025759e614 Merge branch 'wip/jimmac/make-toolbar-togglebuttons-visible' into 'master'
theme: make toggled tbuttons in toolbars visible

Closes #4264

See merge request GNOME/gtk!3959
2021-09-16 11:35:35 +00:00
Jakub Steiner
ed679703b8 theme: make toggled tbuttons in toolbars visible
- do what Alex does in libadwaita

Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/4264
2021-09-16 12:47:26 +02:00
Matthias Clasen
fe46da1bf4 Merge branch 'misc-texture-things' into 'master'
Add gdk_texture_new_from_bytes

See merge request GNOME/gtk!3958
2021-09-16 03:14:12 +00:00
Benjamin Otte
7fd8899092 pixbufutils: Simplify function 2021-09-15 22:00:41 -04:00
Matthias Clasen
9f8d6ff29c texture: Mention download_float in the docs 2021-09-15 22:00:16 -04:00
Matthias Clasen
1230bce133 Add gdk_texture_new_from_bytes
Add this new api, and make gdk_texture_new_from_file
a wrapper around it.
2021-09-15 22:00:09 -04:00
Matthias Clasen
7c2be93a56 Merge branch 'matthiasc/for-master' into 'master'
Fix memorytexture float conversion

See merge request GNOME/gtk!3957
2021-09-16 01:56:39 +00:00
Matthias Clasen
eb23e23b03 ngl: Avoid cairo_to_png in debug output
Just use a GL texture and gdk_texture_save_to_png,
it was made for this.
2021-09-15 21:18:34 -04:00
Matthias Clasen
75b45aeabf Fix memorytexture float conversion
This was silently dropping the alpha in one case.
2021-09-15 21:14:59 -04:00
Matthias Clasen
23ffd6923d Merge branch 'update-readme' into 'master'
Update the README

See merge request GNOME/gtk!3956
2021-09-15 23:25:57 +00:00
Matthias Clasen
d2eb0288d9 Apply 1 suggestion(s) to 1 file(s) 2021-09-15 21:50:36 +00:00
Matthias Clasen
a4b976f7a2 Update the README
Remove the mention of GNU (since that has not been case
for a long time, effectively), state that GTK is hosted
by the GNOME project, and point to GNOME as a place
for donations.
2021-09-15 15:44:57 -04:00
Boyuan Yang
4930faa984 Update Chinese (China) translation 2021-09-15 18:41:06 +00:00
Dz Chen
84fdda4f56 Update Chinese (China) translation 2021-09-15 15:28:39 +00:00
Matthias Clasen
ec6228b3a4 Merge branch 'function-annotations' into 'master'
Annotate gsk_rounded_rect_is_circular as pure

See merge request GNOME/gtk!3952
2021-09-14 21:39:48 +00:00
Matthias Clasen
8b85e7f35a Annotate gtk_get_default_language as const 2021-09-14 16:38:08 -04:00
Matthias Clasen
d7909dccdc Annotate gtk_editable_get_chars as malloc 2021-09-14 16:38:08 -04:00
Matthias Clasen
7773ae4538 csstypes: Add annotations and inlines
Inline _gtk_css_change_for_sibling and
_gtk_css_change_for_child, and mark a few
other functions as const or malloc.
2021-09-14 16:38:08 -04:00
Matthias Clasen
bec44acdeb Annotate some builder apis as malloc 2021-09-14 16:38:08 -04:00
Matthias Clasen
5bfac597f6 Annotate gtk_accelerator_get_default_mod_mask as const 2021-09-14 16:38:08 -04:00
Matthias Clasen
423a4d4c3e Annotate gsk_cairo_blur_compute_pixels as const 2021-09-14 16:38:08 -04:00
Matthias Clasen
38fce67a9b Annotate gdk_rgba_to_string as malloc 2021-09-14 16:38:08 -04:00
Matthias Clasen
04ef7055cd Annotate gdk_drag_action_is_unique as const 2021-09-14 16:38:08 -04:00
Matthias Clasen
44a031c3c1 Annotate gtk_css_tokenizer_get_location as const 2021-09-14 16:38:08 -04:00
Matthias Clasen
be885c888f cssparser: Mark some functions as pure and malloc 2021-09-14 16:38:08 -04:00
Matthias Clasen
6faef4416f Annotate gsk_ngl_uniform_state_align as pure 2021-09-14 16:38:08 -04:00
Matthias Clasen
5f452a5e6c Annotate gsk_rounded_rect_is_circular as pure
And also mark gsk_rounded_rect_to_string as malloc.
2021-09-14 16:38:08 -04:00
Matthias Clasen
060f2d5f65 Annotate pango_glyph_string_num_glyphs as pure 2021-09-14 16:38:08 -04:00
Matthias Clasen
ebca260f2d Annotate gdk_unichar_direction as const 2021-09-14 16:38:08 -04:00
Matthias Clasen
d4b1f85e14 Merge branch 'gsk-tests-gl' into 'master'
testsuite: Call g_test_init in test binaries

See merge request GNOME/gtk!3953
2021-09-14 20:37:16 +00:00
Matthias Clasen
4439ff0c12 testsuite: Stop running tests for the gl renderer
It does not exist anymore.
2021-09-14 16:12:55 -04:00
Matthias Clasen
ffab67ac70 testsuite: Call g_test_init in test binaries
Without it, we mess out on G_DEBUG=fatal-warnings,
so our ci does not alert us that we run a bunch of
tests which spit out warnings.
2021-09-14 16:12:55 -04:00
Lukáš Tyrychtr
0120ff3518 Merge branch 'master' into menu_button_a11y_improvements 2021-09-14 15:34:14 +02:00
Matthias Clasen
2e63b53b1e Merge branch 'fix_accessible_described_by' into 'master'
Fix generation of accessible description in presence of described by relations

See merge request GNOME/gtk!3948
2021-09-14 13:29:28 +00:00
Matthias Clasen
878c9da736 Merge branch 'test-leak-fixes' into 'master'
testsuite: Fix a few memory leaks

See merge request GNOME/gtk!3947
2021-09-14 13:14:10 +00:00
Lukáš Tyrychtr
955d50a080 Fix generation of accessible description in presence of described by relations
The loop going through the relation list should have stopped on the NULL sentinel value, however it never accesed the next list element.
2021-09-14 14:33:30 +02:00
Matthias Clasen
2b4f798e34 testsuite: Fix a few memory leaks
These are keeping the asan build in ci from passing.
2021-09-14 08:29:45 -04:00
Matthias Clasen
cda5d2dadd Merge branch 'tiff-ci' into 'master'
ci: Add libtiff-devel to the image

See merge request GNOME/gtk!3946
2021-09-14 12:27:39 +00:00
Lukáš Tyrychtr
b664b2d1fd Set correct accessible relations for GtkMenuButton
Up until now, as the focus was moved to the inner button, it was not possible for
assistive technologies to determine the correct labels and descriptions
because developers could set them only for the parent widget.
Now, the proper relations are added so the labels should be picked up properly.

Fixes #4254
2021-09-14 14:26:18 +02:00
Matthias Clasen
c70fdd6331 ci: Use the v4 image 2021-09-14 08:06:09 -04:00
Matthias Clasen
ddec3dedd0 ci: Add libtiff-devel to the image
We want to require libtiff in our build.
2021-09-14 08:06:09 -04:00
Matthias Clasen
b1a5c3ff55 Merge branch 'wip/exalm/papercuts' into 'master'
Fix 2 papercuts

See merge request GNOME/gtk!3945
2021-09-14 11:36:25 +00:00
Alexander Mikhaylenko
8f9a5175f0 media-controls: Make play button flat
Match the volume button.
2021-09-14 12:23:03 +05:00
Alexander Mikhaylenko
099c923679 searchbar: Vertically center the close button 2021-09-14 12:22:45 +05:00
Matthias Clasen
2a12a3e6d9 Merge branch 'fix_#4255' into 'master'
stack: Dispose children before emitting items-changed

Closes #4255

See merge request GNOME/gtk!3943
2021-09-13 16:10:37 +00:00
Julian Sparber
cdc1fa166d stack: Dispose children before emitting items-changed
This makes sure that the `GListModel` returned by
`gtk_stack_get_pages()` actually has the items removed before
`items-changed` is emitted.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/4255
2021-09-13 17:19:05 +02:00
Benjamin Otte
f572ca52d2 Merge branch 'wip/otte/texture-threads' into 'master'
gltexture: Make sure downloading textures works in a different thread

See merge request GNOME/gtk!3942
2021-09-13 00:16:30 +00:00
Benjamin Otte
193b383739 ngl: Simplify and unbug texture download
If we can't handle the texture, always just download_texture() it,
that way we are sure it's a memory texture.
2021-09-13 01:56:47 +02:00
Benjamin Otte
6785461c26 gltexture: Make sure downloading textures works in a different thread
This happens in the real world when using the inspector to look at a
node recording of a GStreamer video while the video is still playing.

GStreamer will use the GL context in a different thread while we are
busy trying to download it.

A test is included.
2021-09-13 01:40:03 +02:00
Philipp Kiemle
b9ee9979e7 Update German translation
(cherry picked from commit 17d828fda2)
2021-09-12 21:45:48 +00:00
Benjamin Otte
6bbec87700 Merge branch 'wip/otte/float-textures' into 'master'
Add float texture formats

See merge request GNOME/gtk!3940
2021-09-12 12:55:00 +00:00
Balázs Úr
b35608a351 Update Hungarian translation 2021-09-12 06:03:58 +00:00
Benjamin Otte
416763bf2d testsuite: Add tests for gdk_texture_download_float() 2021-09-12 05:54:37 +02:00
Benjamin Otte
9179ebb28e testsuite: Add memory test support for OpenGL up/downloads
Use a GL renderer to upload textures (and then optionally download them
via release() again). This way, we can test that the GL renderer
properly uploads textures to the right formats (not losing information
for HDR for example) and downloads them again.
2021-09-12 05:54:37 +02:00
Benjamin Otte
bcc17b3033 testsuite: Add tests uploading the memorytextures
Use a GL renderer and render_texture() them.
2021-09-12 05:54:37 +02:00
Benjamin Otte
00439f9e5c testsuite: Rework memorytexture test some more
Instead of predefined colors, generate them randomly.
2021-09-12 05:54:37 +02:00
Benjamin Otte
c9d748fc51 testsuite: Overhaul memorytexture test
Instead of hardcoding pixel values, allow construction of textures by
filling them with GdkRGBA values.
2021-09-12 05:54:37 +02:00
Benjamin Otte
719eafa60c gl: Implement uploading and downloading HDR formats
Also refactor the GL uploading so it does the fallback in a
GLES-compatible way, which means we only need one fallback.
2021-09-12 05:54:37 +02:00
Benjamin Otte
1759d27da9 memorytexture: Add support for HDR formats
Also sanitize the input bytes so the strides match alignment
requirements of the data types.
2021-09-12 05:54:37 +02:00
Benjamin Otte
53275481a5 texture: Add gdk_texture_download_float() 2021-09-12 05:54:37 +02:00
Benjamin Otte
cbe6d0da76 gdk: Deprecate gdk_cairo_draw_from_gl()
It's broken with various pixel formats and OpenGL ES, it's hard to
understand what everything does, and gdk_texture_download() can be used
instead.
2021-09-12 05:54:37 +02:00
Benjamin Otte
c349ed9562 gltexture: Implement download() via glGetTexImage()
1. The download via gdk_cairo_draw_from_gl() was broken sometimes

2. We get easy conversion on fallback by chaining up and using
   download_texture().

3. One more place where Cairo is no longer necessary.
2021-09-12 05:22:21 +02:00
Benjamin Otte
74ce69a8a1 gltexture: Make release() use download_texture()
1. It avoids Cairo, and in particular conversion to Cairo.

2. Keeping a texture allows easy chaining in the vfuncs.

3. Using a texture means releasing will work for HDR formats
   too, once we add them.
2021-09-12 05:22:21 +02:00
Benjamin Otte
4f17f3ac24 texture: Add gdk_texture_download_texture()
A private vfunc that downloads a texture as a GdkMemoryTexture in
whatever format the texture deems best.

There are multiple reasons for this:

 * GLES cannot download the Cairo format. But it can download some
   format and then just delegate to the GdkMemoryTexture implementation.

 * All the other download vfuncs (including the ones still coming) can
   be implemented via download_texture() and delegation, making the
   interface easier.

 * We want to implement image loading and saving support. By using
   download_texture(), we can save in the actual format of the texture.

 * A potential GdkCompressedTexture could be implemented by just
   providing this one vfunc as a compress() step.
2021-09-12 05:22:21 +02:00
Benjamin Otte
9c8e464b04 texture: Add GdkMemoryConversion private enum
Now gdk_memory_convert() converts to one of these conversions instead of
re(ab)using parts of the GdkMemoryFormat enum.
2021-09-12 05:22:21 +02:00
Benjamin Otte
51d0d13a9e gltexture: release() to a texture, not a cairo_surface
This makes forwarding vfuncs a lot easier, because we can just call them
on the texture.
2021-09-12 05:22:21 +02:00
Benjamin Otte
0ee3b1c861 texture: Remove unused argument from vfunc 2021-09-12 05:22:21 +02:00
Balázs Úr
46f88c69a1 Update Hungarian translation 2021-09-11 23:45:21 +00:00
Benjamin Otte
140976a670 Merge branch 'wip/otte/for-master' into 'master'
rendernode: Write the whole node

See merge request GNOME/gtk!3938
2021-09-11 20:56:39 +00:00
Benjamin Otte
9f2b847835 rendernode: Write the whole node
It turns out g_output_stream_write_bytes() does not write the bytes.
It should be renamed to g_output_stream_write_some_of_the_bytes() maybe.
2021-09-11 22:28:40 +02:00
Benjamin Otte
9e11ea699c Merge branch 'hsl' into 'master'
gdk_rgba_parse: Support HSL colors

See merge request GNOME/gtk!3899
2021-09-11 12:57:25 +00:00
Guillaume Bernard
1a4eebe022 Update French translation
(cherry picked from commit 8ffd7e9f87)
2021-09-11 09:41:32 +00:00
Guillaume Bernard
2963468019 Update French translation
(cherry picked from commit f433c543fe)
2021-09-11 09:36:48 +00:00
Matthias Clasen
bfbd95d7d6 Merge branch 'matthiasc/for-master' into 'master'
Stop using config.h.meson

See merge request GNOME/gtk!3936
2021-09-11 02:53:43 +00:00
Matthias Clasen
c1c1d4431d Refactor gdk_gl_context_upload_texture slightly
Introduce a gl_internalformat variable. This will
let us handle more formats in a uniform way in
future commits.
2021-09-10 22:17:31 -04:00
Matthias Clasen
155a4fac5c Add vectorized half-float conversion
We can't make the -4 versions inline, since
we use ifuncs for them, so make vectorized
versions.

Test included.
2021-09-10 22:17:31 -04:00
Matthias Clasen
76f481eb7b Stop using config.h.meson
It isn't necessary and makes us miss defines when
we forget to update it.
2021-09-10 21:08:07 -04:00
James Westman
0782c8a051 gdk_rgba_parse: Support HSL colors 2021-09-10 16:56:42 -05:00
Philipp Kiemle
3d27ff1177 Update German translation
(cherry picked from commit 6228954524)
2021-09-10 19:55:59 +00:00
Matthias Clasen
3ada664a89 Merge branch 'matthiasc/for-master' into 'master'
Fix the testupload test

See merge request GNOME/gtk!3934
2021-09-10 13:54:37 +00:00
Matthias Clasen
643a91bd08 Fix the testupload test
This can only ever have worked by accident.
2021-09-10 08:28:32 -04:00
Emin Tufan Çetin
c86733b4fa Update Turkish translation 2021-09-10 06:40:43 +00:00
Anders Jonsson
55099b7d0e Update Swedish translation 2021-09-08 20:25:27 +00:00
Boyuan Yang
db3858a204 Update Chinese (China) translation 2021-09-05 20:33:21 +00:00
Daniel Șerbănescu
07bff74544 Update Romanian translation
(cherry picked from commit bb72acf9cd)
2021-09-05 18:43:44 +00:00
Daniel Șerbănescu
b4262883a8 Update Romanian translation
(cherry picked from commit 63d829bbc1)
2021-09-05 18:34:37 +00:00
Matthias Clasen
563c85e222 Merge branch 'matthiasc/for-master' into 'master'
inspector: Cosmetics

See merge request GNOME/gtk!3925
2021-09-05 17:26:13 +00:00
Matthias Clasen
d75246a543 inspector: Cosmetics
Make some settings entries smaller, and make the
scales match in size. Also, inline adjustments
in the ui file, since we can do that now.
2021-09-05 12:59:11 -04:00
Matthias Clasen
b3856a3ea0 Merge branch 'matthiasc/for-master' into 'master'
Avoid hand-rolled color glyph information

See merge request GNOME/gtk!3924
2021-09-05 16:12:34 +00:00
Matthias Clasen
bd4d24f8ed Bump pango req to 1.49.1
We are using pango api that was introduced in 1.49.1
without ifdefs, so we should require it.
2021-09-05 10:58:50 -04:00
Matthias Clasen
65ce3eb207 Avoid hand-rolled color glyph information
Followup to b244f31337. Pango provides color glyph
information for us now, so we don't need to steal a
bit anymore.
2021-09-05 10:58:50 -04:00
Anders Jonsson
865ac44963 Update Swedish translation
(cherry picked from commit 19af960163)
2021-09-05 14:11:51 +00:00
Yaron Shahrabani
55a935db53 Update Hebrew translation 2021-09-05 13:45:49 +00:00
Matthias Clasen
6fefae3dbb Merge branch 'better-font-rendering-demo' into 'master'
gtk-demo: Improve the font rendering demo

See merge request GNOME/gtk!3923
2021-09-05 04:21:29 +00:00
Matthias Clasen
f7c84ddc7f gtk-demo: Font rendering - Add some bling
Fade the outlines and pixels in and out.
2021-09-04 23:41:44 -04:00
Matthias Clasen
f4a4dd2615 gtk-demo: Font rendering - expand docs 2021-09-04 23:05:55 -04:00
Matthias Clasen
b718d99d1f gtk-demo: Font rendering - Add keynav
Add mnemonics to most controls, and make
Ctrl+/- change the zoom.
2021-09-04 23:00:17 -04:00
Matthias Clasen
c7215d1199 gtk-demo: Font rendering - add outlines
Should outlines as well.
2021-09-04 22:56:07 -04:00
Matthias Clasen
24d69ef125 gtk-demo: Font rendering - better start
Turn antialiasing on initially, and turn the
extents and grid off. Otherwise we show pretty
shocking rendering right from the start.
2021-09-04 22:56:07 -04:00
Matthias Clasen
7c3fbdecf2 gtk-demo: Font rendering - improve the grid
Allow changing the character shown in the grid.
2021-09-04 22:56:07 -04:00
Matthias Clasen
b77938f40f Cosmetics
Remove an unused object from the font rendering
demo ui file.
2021-09-04 22:55:47 -04:00
Matthias Clasen
f703744564 Merge branch 'ebassi/accel-parse-doc' into 'master'
Improve the gtk_accelerator_parse() docs

See merge request GNOME/gtk!3921
2021-09-04 23:39:10 +00:00
Matthias Clasen
a3ccff3773 Merge branch 'text-fixes' into 'master'
textview: fix pango context invalidation

See merge request GNOME/gtk!3922
2021-09-04 21:39:30 +00:00
Asier Sarasua Garmendia
9869082c1c Update Basque translation
(cherry picked from commit 0768addbb3)
2021-09-04 20:54:41 +00:00
Matthias Clasen
754212d0f9 textview: Invalidate Pango contexts
We need to invalidate the Pango contexts when
font settings change. Use the new helper
gtk_widget_update_pango_context to make it less
likely that we forget to update some things.
2021-09-04 15:42:05 -04:00
Matthias Clasen
a9b81577c6 widget: Provide a helper for updating pango contexts 2021-09-04 15:42:05 -04:00
Matthias Clasen
eaa2dada54 Rename an internal function
It occupies a name I want to reuse for something else.
2021-09-04 15:42:05 -04:00
Matthias Clasen
ce2b2128bb Revert "gsk: Add font options to text nodes"
This reverts commit f1347f5841.
2021-09-04 15:42:05 -04:00
Matthias Clasen
41c25b8809 Revert "gsk: Add font options to the glyph cache"
This reverts commit 6599cb001f.
2021-09-04 15:42:05 -04:00
Matthias Clasen
b5ff35ff3e Revert "gsk: Pass font options along"
This reverts commit 299c7c3514.
2021-09-04 15:42:05 -04:00
Matthias Clasen
06423d807f Revert "gtk: Pass font options along"
This reverts commit 062a15310a.
2021-09-04 15:42:05 -04:00
Goran Vidović
0395395d52 Update Croatian translation
(cherry picked from commit 6fe3b21a01)
2021-09-04 18:12:03 +00:00
Emmanuele Bassi
c3ca48b249 Improve the gtk_accelerator_parse() docs
We need to escape the modifiers in angular brackets, or Markdown will
consider them as HTML tags.

We also should document the modifiers we're parsing.
2021-09-04 18:56:08 +01:00
Boyuan Yang
464e0aed04 Update Chinese (China) translation 2021-09-04 17:38:16 +00:00
Goran Vidović
d46e4fcecd Update Croatian translation
(cherry picked from commit 543b7defec)
2021-09-04 17:16:26 +00:00
Changwoo Ryu
363fb96e81 Update Korean translation 2021-09-04 09:02:48 +00:00
Changwoo Ryu
2382bd3bb2 Update Korean translation
(cherry picked from commit 0a5af76932)
2021-09-04 08:59:40 +00:00
Anders Jonsson
3b0a9e84ab Update Swedish translation
(cherry picked from commit 2dbcad428a)
2021-09-03 22:59:37 +00:00
Matthias Clasen
850aebea5d Merge branch 'matthiasc/for-master' into 'master'
widget: Redraw when font options change

See merge request GNOME/gtk!3917
2021-09-03 18:16:33 +00:00
Matthias Clasen
26e632e549 widget: Redraw when font options change
Its the right thing to do, even if it is a rare event.
2021-09-03 13:56:29 -04:00
Matthias Clasen
64d2d7074f Merge branch 'small-text-fixes' into 'master'
gsk: Pass font options down

See merge request GNOME/gtk!3908
2021-09-03 17:21:08 +00:00
Matthias Clasen
062a15310a gtk: Pass font options along
Pass the widget's font options along when we
are creating text nodes.
2021-09-03 12:52:05 -04:00
Matthias Clasen
299c7c3514 gsk: Pass font options along
Use the font options from the text node when
looking up glyphs.
2021-09-03 12:52:05 -04:00
Matthias Clasen
6599cb001f gsk: Add font options to the glyph cache
The cairo_t that we create to render glyphs for
the glyph cache needs to match the font options
that are supposedly governing how glyphs are
drawn.

Since we allow font options to be different per
widget in gtk, we need to have them at least at
the level of individual render nodes. Adding them
to the lookup key for the glyph cache has the
side effect of solving another problem: We are
not flushing the cache when font options change.
2021-09-03 12:52:05 -04:00
Matthias Clasen
f1347f5841 gsk: Add font options to text nodes
Since font options affect how the glyphs get rendered,
we need to pass the font options down from the gtk level
to where the glyph cache is populated.

Add a new gsk_text_node_new_full api that takes a
cairo_font_options_t in addition to the other parameters.
2021-09-03 12:43:35 -04:00
Matthias Clasen
f3ccf62463 gtk-demo: Improve the font rendering demo
Add a toggle for antialiasing, and make the metrics
hinting turn on rounding of positions, to match what
we do with settings now.
2021-09-03 11:29:44 -04:00
Matthias Clasen
44fea33c5d Merge branch 'wip/exalm/buttons' into 'master'
Allow custom children on GtkMenuButton

Closes #4205

See merge request GNOME/gtk!3904
2021-09-03 14:49:09 +00:00
Alexander Mikhaylenko
8b48cf11f9 menubutton: Support custom children
Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/4205
2021-09-03 17:52:46 +05:00
Matthias Clasen
e681fdd958 Merge branch 'matthiasc/for-master' into 'master'
Add a README in gtk/compose

See merge request GNOME/gtk!3916
2021-09-03 00:55:45 +00:00
Matthias Clasen
d4b7a78c54 Add a README in gtk/compose 2021-09-02 20:10:19 -04:00
Matthias Clasen
a45cbad553 Merge branch 'wip/smcv/transparent-is-transparent' into 'master'
reftest-compare: Treat colour channels as undefined if alpha is zero

Closes #4227

See merge request GNOME/gtk!3914
2021-09-02 22:19:27 +00:00
Simon McVittie
16b9a30655 reftest-compare: Treat colour channels as undefined if alpha is zero
If the alpha channel is zero, it doesn't matter what the values of the
red, green and blue channels are: the pixel is still fully transparent.
On most architectures, fully transparent pixels end up all-zeroes
(fully transparent black), matching what's in the reference PNG file;
but on mips*el the blend-difference and blend-normal tests get all-ones
(fully transparent white) and a test failure.

Resolves: https://gitlab.gnome.org/GNOME/gtk/-/issues/4227
Signed-off-by: Simon McVittie <smcv@debian.org>
2021-09-02 22:34:48 +01:00
Jiri Grönroos
82a184a7b7 Update Finnish translation
(cherry picked from commit 33a4ae12ef)
2021-09-02 16:06:57 +00:00
Aurimas Černius
9e198a59b6 Updated Lithuanian translation 2021-09-02 13:51:39 +03:00
Matthias Clasen
c002678085 Merge branch 'fix-gst-subproject' into 'master'
media: Check for gstreamer verion instead of using cc.links()

See merge request GNOME/gtk!3910
2021-09-02 01:33:06 +00:00
Matthias Clasen
486cffc361 Merge branch 'hint-metrics-setting' into 'master'
Add a gtk-hint-font-metrics setting

See merge request GNOME/gtk!3912
2021-09-01 23:15:50 +00:00
Matthias Clasen
67495fcc77 Update settings tests
We have a new setting, so the test that is counting
settings needs an update.
2021-09-01 17:16:08 -04:00
Matthias Clasen
b26a370ce4 Add a gtk-hint-font-metrics setting
This lets people switch back to font rendering that is closer
to what GTK 3 does. It is not perfect - subpixel antialiasing
is not going to work. But it give us an Escape hatch while
we shake out the bugs in our linear layout.

Related: #3787
2021-09-01 15:52:07 -04:00
Matthias Clasen
4dc0e67ac7 Merge branch 'color-glyph-info' into 'master'
Use color glyph information from Pango

See merge request GNOME/gtk!3909
2021-09-01 16:59:38 +00:00
Xavier Claessens
2c060663cf media: Check for gstreamer verion instead of using cc.links()
This fix error when gstgl_dep comes from a subproject because in that
case it cannot be used in compiler checks.
2021-09-01 12:04:05 -04:00
Matthias Clasen
76a8eb4960 Merge branch 'matthiasc/for-master' into 'master'
Initial support for new Pango attributes

See merge request GNOME/gtk!3911
2021-09-01 15:06:26 +00:00
Matthias Clasen
ad3dad1965 Initial support for new Pango attributes
This is still missing the GtkTextTag hookup,
but it fixes the build.
2021-09-01 10:32:45 -04:00
Danial Behzadi
172d97de05 Update Persian translation 2021-09-01 09:42:39 +00:00
Daniel Mustieles
4c967d5b45 Updated Spanish translation 2021-09-01 11:02:13 +02:00
Matthias Clasen
b244f31337 Use color glyph information from Pango
Pango now sets a bit in PangoGlyphVisAttr for
color glyphs, so we don't need to do that
ourselves anymore.
2021-09-01 01:47:06 -04:00
Nathan Follens
8550a04bf4 Update Dutch translation
(cherry picked from commit 9aa08dd1b8)
2021-08-31 15:55:14 +00:00
eshagh shahidani
cb38ead48e Update Persian translation
(cherry picked from commit 7691c94a37)
2021-08-31 14:42:34 +00:00
Matthias Clasen
9713c3394d Merge branch 'matthiasc/for-master' into 'master'
editable: Clarify the docs

See merge request GNOME/gtk!3906
2021-08-31 13:15:47 +00:00
Matthias Clasen
fa57b006c9 editable: Clarify the docs
Make it clear that your class must have all the editable properties
already before you call the (confusingly named) function
gtk_editable_install_properties.
2021-08-31 08:41:45 -04:00
Matthias Clasen
9f73f0234a Merge branch 'default-settings-non-debug' into 'master'
Revert "reftests: Enforce default settings"

See merge request GNOME/gtk!3903
2021-08-30 18:09:28 +00:00
Matthias Clasen
a4f067481c gdk: Make GDK_DEBUG=default-settings unconditional
Our tests use this settings, so we should respect it
in non-debug builds as well.
2021-08-30 11:01:55 -04:00
Matthias Clasen
733fb527fa Revert "reftests: Enforce default settings"
This reverts commit 4e4f57e091.

This should not be necessary, since we have GDK_DEBUG=default-settings.
2021-08-30 11:01:22 -04:00
Matthias Clasen
3667c6b053 Merge branch 'wip/smcv/compose-files' into 'master'
Fix Compose handling on big-endian host architectures

Closes #4217

See merge request GNOME/gtk!3902
2021-08-30 12:52:54 +00:00
Simon McVittie
1071818df8 compose: Update sequences from libX11 1.7.2
This adds support for sequences like <Compose>,G,u -> capital G with
breve. Previously, only a capital U was accepted for E, G, I and O
(but a lower-case u was accepted for A and U for some reason).

Signed-off-by: Simon McVittie <smcv@debian.org>
2021-08-30 13:09:27 +01:00
Simon McVittie
11c2d9ea30 compose: Document how to get compose-parse input from libX11 source
Signed-off-by: Simon McVittie <smcv@debian.org>
2021-08-30 13:09:05 +01:00
Simon McVittie
52cdf3056d compose: Generate endian-dependent compact Compose data
The GtkComposeTable cache is always in big-endian format and is
byteswapped on load for the more common little-endian CPUs, but
init_builtin_table() in GtkIMContextSimple can't byteswap the built-in
data without copying it, which is undesirable. Pregenerate both big-
and little-endian compose data, and compile the correct flavour into
each build of GTK. This fixes failure of the composetable test when
building for a big-endian architecture such as s390x and (traditional,
big-endian) powerpc.

Resolves: https://gitlab.gnome.org/GNOME/gtk/-/issues/4217
Signed-off-by: Simon McVittie <smcv@debian.org>
2021-08-30 11:29:46 +01:00
Benjamin Otte
32899a1edd Merge branch 'wip/otte/for-master' into 'master'
fontbutton: Make sure the window is on the same display

See merge request GNOME/gtk!3901
2021-08-30 04:37:49 +00:00
Benjamin Otte
119458f13e contentdeserializer: Fix some API awkwardness
Allow uninitialized GValues to be passed. Makes life easier for the
inspector code I'm writing.
2021-08-30 06:02:16 +02:00
Benjamin Otte
2863095f06 node-editor: Allow dragging and dropping the center picture
Dragging will just drag the render node.

Dropping will replace the current contents of the textview with the
dropped node.

Neat side effect: You can drag the node onto itself to do a
deserialize/serialize of the current text.
2021-08-30 06:02:16 +02:00
Benjamin Otte
cbc050b9ed recorder: Make the render nodes in the list draggable
You can (soon) drag any of the nodes directly into the node-editor.
2021-08-30 06:02:16 +02:00
Benjamin Otte
18affbd390 dragicon: Add a default drag icon for GskRenderNode
Somebody should make this default drag icon machinery pluggable.
2021-08-30 06:02:16 +02:00
Benjamin Otte
0b7a36ce33 rendernode: Add (de)serialization support for render nodes
This includes our own new mime type for render nodes, too.
2021-08-30 06:02:15 +02:00
Benjamin Otte
1957915940 rendernode: Add GValue functions for render nodes
This is needed as GskRenderNode is its own fundamental type and has its
own GValue infrastructure. And I want to put render nodes into the
clipboard which uses GValues.
2021-08-30 06:02:15 +02:00
Benjamin Otte
552b71d4e2 stylecontext: Remove unneeded headers 2021-08-30 06:02:15 +02:00
Benjamin Otte
480112f9aa fontbutton: Destroy dialog in unrealize()
This way, we can be sure it's always using the right display.

We can also be sure that it doesn't leak.
2021-08-30 06:02:15 +02:00
Benjamin Otte
9a2f4d8026 fontbutton: Make sure the window is on the same display
We don't want the font buttons created by the inspector to run on the
default display.
2021-08-30 06:02:15 +02:00
Benjamin Otte
3b15f32335 Merge branch 'wip/otte/symbolic-paintable' into 'master'
Add GtkSymbolicPaintable

See merge request GNOME/gtk!3895
2021-08-30 03:54:35 +00:00
Benjamin Otte
7404a6fc4f Merge branch 'wip/otte/G_TYPE_POINTER' into 'master'
Get rid of G_TYPE_POINTER

See merge request GNOME/gtk!3900
2021-08-30 03:50:30 +00:00
Benjamin Otte
91d1ec41c2 symbolicpaintable: Refactor default colors path 2021-08-30 05:29:04 +02:00
Benjamin Otte
9237c8be67 icontheme: Refactor gtk_icon_theme_lookup_symbolic_colors()
With the new enum, the code looks much cleaner.
2021-08-30 04:52:47 +02:00
Benjamin Otte
6c87d362c5 enums: Add a GtkSymbolicColor enum
That way we don't nedmagic numbres to index the colors array.

Use it in the symbolic paintable demo.
2021-08-30 04:36:16 +02:00
Baurzhan Muftakhidinov
4f31d3587d Update Kazakh translation
(cherry picked from commit 37d2d407a1)
2021-08-29 17:09:01 +00:00
Baurzhan Muftakhidinov
29a2f4021a Update Kazakh translation
(cherry picked from commit 9e62fd82ea)
2021-08-29 07:41:58 +00:00
Benjamin Otte
e2d321a16a searchengine: Rename private headers
The code uses G_TYPE_POINTER and I got all sorts of scared.
2021-08-29 06:52:28 +02:00
Benjamin Otte
7366f5099a filesystemmodel: Don't use G_TYPE_POINTER
It's a GError, use G_TYPE_ERROR.
2021-08-29 06:52:28 +02:00
Benjamin Otte
4fbef5f466 placessidebar: Don't use G_TYPE_POINTER
We have a type for lists of GFiles. We invented it for DND.

Keep the annotation info, so bindings don't have to know this.
2021-08-29 06:52:28 +02:00
Benjamin Otte
2e48ff3362 pathbar: Use correct GType in signal 2021-08-29 06:52:28 +02:00
Benjamin Otte
7cdbdb663c gtk-demo: Add a symbolic paintable demo
Don't click the button!
2021-08-29 04:29:53 +02:00
Benjamin Otte
1b390d3857 gtk-demo: Explicitly pass nuclear icon colors 2021-08-29 04:29:53 +02:00
Benjamin Otte
2808f9c75b gtk: Port icontheme to GtkSymbolicPaintable 2021-08-29 04:29:53 +02:00
Benjamin Otte
49d109c29e gtk: Add the GtkSymbolicPaintable interface 2021-08-29 04:29:53 +02:00
Benjamin Otte
36dd959bf9 build: Check that introspection is enabled for docs build 2021-08-29 04:29:53 +02:00
Benjamin Otte
2f9a67b8a1 docs: Fix vfunc references
vfunc references should just use the object name, not the
class/interface/iface name.
2021-08-29 04:29:02 +02:00
Matthias Clasen
6d5d9ea073 Merge branch 'text-selection-missing' into 'master'
ngl: Avoid a coordinate overflow

Closes #4214

See merge request GNOME/gtk!3897
2021-08-28 21:21:02 +00:00
Matthias Clasen
1cfd340cae ngl: Avoid a coordinate overflow
This was showing up as big text selections going
missing sporadically.

Fixes: #4214
2021-08-28 15:42:30 -04:00
Matthias Clasen
369ccfc34f Merge branch 'matthiasc/for-master' into 'master'
Draw negatively sloped carets correctly

See merge request GNOME/gtk!3892
2021-08-28 17:18:21 +00:00
Matthias Clasen
e556513de6 Merge branch 'menu-accel' into 'master'
window: Prefer menu bars when handling F10

See merge request GNOME/gtk!3893
2021-08-28 17:17:43 +00:00
Matthias Clasen
79dc1a2a4d Merge branch 'randr' into 'master'
x11: Fix handling of `RRScreenChangeNotify`/`RRNotify` events

See merge request GNOME/gtk!3894
2021-08-28 17:17:00 +00:00
Ian Douglas Scott
9e5a501c73 x11: Fix handling of RRScreenChangeNotify/RRNotify events
It seems these are sent with `xwindow` set to the root window, so this
was failing to find a surface and get the screen from that.

I'm not sure if there's a reason not to get the screen this way
elsewhere in the function, but it seems this should be correct.

This fixes the behavior of `gdk_x11_display_get_monitors()`, which
wasn't correctly changing when monitors were added or removed. For
instance, this python code was always showing the same number of
monitors when one was turned off and on, but updates correctly with this
change applied:

```python
import gi
gi.require_version("GLib", "2.0")
gi.require_version("Gdk", "4.0")
gi.require_version("Gtk", "4.0")
from gi.repository import GLib, Gdk, Gtk

def f():
    print(len(Gdk.Display.get_default().get_monitors()))
    return True
GLib.timeout_add_seconds(1, f)

GLib.MainLoop().run()
```
2021-08-27 18:07:39 -07:00
Enrico Nicoletto
2db8d7f6a2 Update Brazilian Portuguese translation
(cherry picked from commit cd9735eab1)
2021-08-28 01:00:39 +00:00
Enrico Nicoletto
94c3f4d4fc Update Brazilian Portuguese translation
(cherry picked from commit 8f5a1471cc)
2021-08-28 00:44:38 +00:00
Florian Müllner
3fa26861cd window: Prefer menu bars when handling F10
Focusing the first widget in the titlebar is a good fallback,
but a "real" menubar or :primary menu button should take
precedence.
2021-08-28 00:19:23 +02:00
Matthias Clasen
ef2b0ccd6c Draw negatively sloped carets correctly
The code for handling negatively sloped caret
positions was not tested, and naturally did
not work. Fix it.
2021-08-27 17:20:35 -04:00
Matthias Clasen
f1702d24e7 Merge branch 'css-line-decoration' into 'master'
textview: Apply line decoration from css

See merge request GNOME/gtk!3890
2021-08-27 01:37:57 +00:00
Matthias Clasen
3a50ff57d8 Clean up the code
Avoid compiler warnings, and make the code
a bit more compact.
2021-08-26 20:45:17 -04:00
Matthias Clasen
8ac2e8d495 textview: Apply font features from css
We were forgetting to propagate these values from
CSS to the default attributes. Share the code for
getting these values out of a GtkCssStyle.
2021-08-26 20:21:23 -04:00
Matthias Clasen
e56cf85fd1 textview: Apply text transform from css
We were forgetting to propagate these values from
CSS to the default attributes.
2021-08-26 18:53:30 -04:00
Matthias Clasen
1c6aef1862 textview: Apply line decoration from css
We were forgetting to propagate these values from
CSS to the default attributes.
2021-08-26 18:46:57 -04:00
Matthias Clasen
4653cbe56e Merge branch 'css-letter-spacing' into 'master'
textview: Don't forget to collect css letterspacing

Closes #4207

See merge request GNOME/gtk!3889
2021-08-26 19:37:55 +00:00
Matthias Clasen
93148d302f textview: Don't forget to collect css letterspacing
There are more properties missing, this is just
the start.

Fixes: #4207
2021-08-26 15:01:23 -04:00
Andika Triwidada
a443ba91ce Update Indonesian translation
(cherry picked from commit 85ad1db8ef)
2021-08-26 14:40:16 +00:00
Hugo Carvalho
d8daef2de7 Update Portuguese translation
(cherry picked from commit 6e467de751)
2021-08-26 14:30:04 +00:00
Hugo Carvalho
845d43c77a Update Portuguese translation
(cherry picked from commit ae5b6395ad)
2021-08-26 14:12:59 +00:00
Andika Triwidada
f8dbcc472b Update Indonesian translation
(cherry picked from commit dcc899b621)
2021-08-26 13:39:00 +00:00
Marek Černocký
0f0f75f6b1 Updated Czech translation 2021-08-26 15:07:54 +02:00
Timm Bäder
4e2e2d84fc Merge branch 'clang-fallthrough' into 'master'
build: fix implicit-fallthrough errors with clang

See merge request GNOME/gtk!3887
2021-08-26 11:15:28 +00:00
Jordi Mas
887885b6e0 Update Catalan translation 2021-08-26 13:10:32 +02:00
Matthias Clasen
a868a5c434 Merge branch 'matthiasc/for-master' into 'master'
More markup demos

See merge request GNOME/gtk!3888
2021-08-26 06:15:06 +00:00
Christoph Reiter
a0c147d246 build: fix implicit-fallthrough errors with clang
The clang build fails due to -Werror=implicit-fallthrough being
on by default and some fallthrough cases not being marked as such.

Use G_GNUC_FALLTHROUGH or duplicate the code in those cases.
2021-08-26 07:08:38 +02:00
Matthias Clasen
38040c96d6 More markup demos
Showing more of what Pango can do.
2021-08-25 19:38:59 -04:00
Matthias Clasen
989ecf69ad Merge branch 'new-pango-attributes' into 'master'
Support new pango attributes

See merge request GNOME/gtk!3878
2021-08-25 20:11:45 +00:00
Matthias Clasen
9d26399143 Merge branch 'treeexpander-claim-gestures' into 'master'
GtkTreeExpander: claim expander-icon gestures

Closes #4199

See merge request GNOME/gtk!3886
2021-08-25 19:11:23 +00:00
Matthias Clasen
b9cad7cc54 textview: Implement new pango attributes
Implement the word and sentence attributes.
2021-08-25 14:57:13 -04:00
Matthias Clasen
357b97b5a6 Support new pango attributes
Support new Pango attributes for segmentation
in GtkBuilder.
2021-08-25 14:57:13 -04:00
Jan Lukas Gernert
318160d836 GtkTreeExpander: claim expander-icon gestures
Claim the pressed, released and canceled gestures
meant for the expander-icon of the TreeExpander.
This avoids selecting the row when expanding or collapsing it.

Closes #4199
2021-08-25 17:50:12 +02:00
Matthias Clasen
5e90d63373 Merge branch 'sloped-caret' into 'master'
Implement sloped caret drawing

See merge request GNOME/gtk!3880
2021-08-25 13:43:24 +00:00
Jordi Mas
0b7f1e488f Update Catalan translation 2021-08-25 15:17:27 +02:00
Matthias Clasen
e281bbbb55 Merge branch 'treeexpander-indent-property' into 'master'
GtkTreeExpander: indent-without-expander property

Closes #4175

See merge request GNOME/gtk!3858
2021-08-25 11:48:59 +00:00
Matthias Clasen
892bacee52 Merge branch '4195-include-gdkprivate-h' into 'master'
gdkmacoseventsource: Include "gdk-private.h"

Closes #4195

See merge request GNOME/gtk!3882
2021-08-25 11:48:11 +00:00
Matthias Clasen
2f1db4b77c Use pango_layout_get_caret_pos
This new api returns rectangles for sloped carets,
in contrast to pango_layout_get_cursor_pos, which
always returns a rectangle with a width of zero.
2021-08-25 06:53:53 -04:00
Matthias Clasen
f90e9b26f8 Implement sloped caret drawing
Prepare for Pango to return slope information for carets.

While we are at it, improve the shape of our carets a bit.
2021-08-25 06:53:53 -04:00
Matthias Clasen
ad71f454bd Merge branch 'fix-gettext' into 'master'
Fix wrong gettext ITS target

See merge request GNOME/gtk!3881
2021-08-25 10:51:57 +00:00
Rafał Dzięgiel
c66bd791c4 Fix wrong gettext ITS target
The installed ITS rule filename is "gtk4builder.its". The .loc file
is wrongly pointing to old "gtkbuilder.its" which makes gettext fail
on systems without GTK3 installed.
2021-08-25 10:08:50 +02:00
Fran Dieguez
40bceef3ca Update Galician translation
(cherry picked from commit 410ea1049b)
2021-08-25 07:26:55 +00:00
Fran Dieguez
9d79f55dc9 Update Galician translation
(cherry picked from commit 09a5828ccf)
2021-08-25 06:12:43 +00:00
Matthias Clasen
c5c1cf6d55 Merge branch 'wip/otte/for-master' into 'master'
wayland: Better error on eglGetDisplay() failure

See merge request GNOME/gtk!3879
2021-08-25 04:24:55 +00:00
Peter Bloomfield
9eb8aa9a32 gdkmacoseventsource: Include "gdk-private.h"
_gdk_macos_event_source_new() calls g_source_set_static_name(), which
for GLib versions before 2.69.1 is a macro defined in gdk-private.h.

Fixes #4195

modified:   gdk/macos/gdkmacoseventsource.c
2021-08-24 16:55:52 -04:00
Benjamin Otte
95931a7e6c wayland: Better error on eglGetDisplay() failure
Goals:

1. Provide as much information as possible in the error message, so
   users can try to fix their system themselves.
2. Try to formulate the error message in a way that explains that this
   is not something GTK can fix, but a lower layer problem.

Related: #4193
2021-08-24 19:55:22 +00:00
Yuri Chornoivan
d9daaed43f Update Ukrainian translation
(cherry picked from commit 6377b23bd6)
2021-08-24 17:29:02 +00:00
Matthias Clasen
b9c51e65c1 Merge branch 'wip/carlosg/gesture-state-in-entries' into 'master'
Claim clicks further at GtkEntry/GtkSearchEntry

See merge request GNOME/gtk!3873
2021-08-24 17:20:20 +00:00
Matthias Clasen
da5eb92f47 Merge branch 'matthiasc/for-master' into 'master'
Revert "imwayland: Tweak preedit text"

Closes #4123

See merge request GNOME/gtk!3877
2021-08-24 17:19:42 +00:00
Matthias Clasen
03ed585f6f tests: Rewrite PangoAttribute introspection
We can use the new binding helpers to make this
a little less bothersome. That way, it will need
tweaks less often (only when new fundamental types
are introduced).
2021-08-24 12:53:48 -04:00
Matthias Clasen
51f953a1aa Revert "imwayland: Tweak preedit text"
This reverts commit d84a028455.

IBus uses the same character now.

Fixes: #4123
2021-08-24 12:53:48 -04:00
Emmanuele Bassi
93fb07d808 Merge branch 'expander-ref-leak' into 'master'
Release an extra reference on GtkExpander:child

See merge request GNOME/gtk!3876
2021-08-24 13:20:48 +00:00
Emmanuele Bassi
5e311d4d85 Release an extra reference on GtkExpander:child
The child of a GtkExpander is owned directly by the expander whenever
the "expanded" flag is unset.

We are adding an additional reference to the child of an expander when
expander is not expanded.

Additionally, if a GtkExpander is disposed while not expanded, we need
to explicitly release the reference on the child widget that we own.

This reference leak was masked in GTK3 by GtkContainer removing each
child from the parent container by recursively calling
gtk_widget_destroy().
2021-08-24 11:28:59 +01:00
Carlos Garnacho
e652054d50 gtkpasswordentry: Add a "catchall" click gesture handler
This gesture is set on the whole widget surface, since there's
multiple input targets inside an entry (icons, the GtkText itself)
it makes sense to consider the full entry an area handling clicks.
Ensure these events don't propagate further up, and result in other
actions.
2021-08-24 01:13:29 +02:00
Carlos Garnacho
58c31b8627 gtkpasswordentry: Consume click events after pressing on icon
This may result in user actions, so the gesture should consume the
events.
2021-08-24 01:12:31 +02:00
Matthias Clasen
b945033b41 Merge branch 'fix-docs' into 'master'
Fix documentation for gtk_icon_view_create_drag_icon

Closes #4190

See merge request GNOME/gtk!3875
2021-08-23 20:40:17 +00:00
Qiu Wenbo
92d2867170 docs: Fix documentation for gtk_icon_view_create_drag_icon
Fixes: #4190
2021-08-24 00:24:08 +08:00
Matthias Clasen
5d38c8c558 Merge branch 'wip/kalev/pre-compiled-css-detection' into 'master'
build: Fix detection for pre-compiled css files

See merge request GNOME/gtk!3874
2021-08-23 14:57:19 +00:00
Kalev Lember
552a4b2c82 build: Fix detection for pre-compiled css files
The default theme changed from Adwaita to Default and this tripped up
the logic to detect if the tarball builds contain pre-built css files or
not. Fix this by looking at pre-compiled css files in themes/Default/
instead of themes/Adwaita/.
2021-08-23 16:15:48 +02:00
Carlos Garnacho
7a4afb08bd gtksearchentry: Add a "catchall" click gesture handler
This gesture is set on the whole widget surface, since there's
multiple input targets inside an entry (icons, the GtkText itself)
it makes sense to consider the full entry an area handling clicks.
Ensure these events don't propagate further up, and result in other
actions.
2021-08-23 15:38:33 +02:00
Carlos Garnacho
c5cd1ac630 gtkentry: Add a "catchall" click gesture handler
This gesture is set on the whole widget surface, since there's
multiple input targets inside an entry (icons, the GtkText itself)
it makes sense to consider the full entry an area handling clicks.
Ensure these events don't propagate further up, and result in other
actions.
2021-08-23 15:38:33 +02:00
Carlos Garnacho
90edb76415 gtksearchentry: Consume click events after pressing on icon
This results in user actions, so the gesture should consume the
events.
2021-08-23 15:38:33 +02:00
Carlos Garnacho
8f397502df gtktext: Set claimed state on button1 click gesture
All possible ramifications after button1 press (move cursor,
begin drag, begin dnd, select word/line, ...) result in user
actions. The right thing after that is consuming the events,
set the gesture state for that.
2021-08-23 15:28:27 +02:00
Jan Lukas Gernert
1cb17d8613 GtkTreeExpander: indent-for-icon property
A property to determine if the TreeExpander should indent the child
by the width of an expander-icon when it is not expandable.

Closes #4175
2021-08-23 07:54:45 +02:00
Jan Lukas Gernert
88e796bb45 Add 4.6 version macros 2021-08-23 07:54:27 +02:00
Matthias Clasen
1310bf0218 Merge branch 'matthiasc/for-master' into 'master'
NEWS: Updates

See merge request GNOME/gtk!3872
2021-08-22 21:16:02 +00:00
Matthias Clasen
4efeaa844f NEWS: Updates 2021-08-22 16:41:22 -04:00
Matthias Clasen
24685612a9 Merge branch 'css-text-transform' into 'master'
css: Implement text-transform

See merge request GNOME/gtk!3862
2021-08-22 20:40:50 +00:00
Matthias Clasen
bf21df4195 Add an example for text transforms
Show some transformed text in the markup demo.
2021-08-22 15:57:50 -04:00
Matthias Clasen
417b3f9c6b Implement text transforms for GtkTextView
Add a property to GtkTextTag and do all the
legwork to translate it to the Pango attribute.
2021-08-22 15:57:50 -04:00
Matthias Clasen
2d84a1c63e css: Implement text-transform
Implement the text-transform property from
https://www.w3.org/TR/css-text-3/#text-transform-property
using a new Pango attribute.
2021-08-22 15:57:50 -04:00
Matthias Clasen
5ab9a29bc4 Merge branch 'bump-pango' into 'master'
Bump the pango dependency

See merge request GNOME/gtk!3871
2021-08-22 19:57:21 +00:00
Matthias Clasen
383ea0d86a Merge branch 'css-line-height2' into 'master'
Implement CSS line-height

See merge request GNOME/gtk!3833
2021-08-22 19:47:10 +00:00
Matthias Clasen
df8f75bb8f Merge branch 'matthiasc/for-master' into 'master'
windowhandle: Quiet a compiler warning

See merge request GNOME/gtk!3868
2021-08-22 19:28:01 +00:00
Matthias Clasen
ba95ef63da Drop PANGO_VERSION_CHECK checks
We require Pango 1.49 now.
2021-08-22 15:26:23 -04:00
Matthias Clasen
bea4aa31ea Bump Pango dep
Require Pango 1.49, so we can support new attributes
without too much ifdeffery.
2021-08-22 15:23:42 -04:00
Matthias Clasen
6c19a8352f gtk-demo: Add a line height demo
Add an example for widely spaced text to the markup demo.
2021-08-22 15:15:50 -04:00
Matthias Clasen
e3df89b524 gtk-demo: Improve markup demo
The font sizes demo had the space between the font-size spans,
causing us to have a run with just a default sized space between
the words, which in turn leads to wobbly cursor sizes. Avoid that
by including the space in the preceding span.

Also, make it bigger.
2021-08-22 15:15:50 -04:00
Matthias Clasen
a9003f7ac0 gtk-demo: Set line height from markup
Keep the import-markup code in sync with GtkTextBuffer.
2021-08-22 15:15:50 -04:00
Matthias Clasen
2cc06f60c5 textview: Set line height from markup
Note that we ignore the absolute-line-height
attribute for now.
2021-08-22 15:15:50 -04:00
Matthias Clasen
4759afcc3e textview: Set line height from css
Set the line height in the default attributes from
the CSS style. This makes line height work in
GtkTextView.
2021-08-22 15:15:50 -04:00
Matthias Clasen
66b297e408 textview: Add line height plumbing
This adds a line-height property to GtkTexttag and a
line_height field to GtkTextAttributes, and translates
it to a pango attribute.
2021-08-22 15:15:50 -04:00
Matthias Clasen
bbd2b255a3 css: Document line-height as supported 2021-08-22 15:15:50 -04:00
Matthias Clasen
8b2f28eee3 css: Add parser tests for line-height 2021-08-22 15:15:50 -04:00
Matthias Clasen
ae767dc5bf css: Translate line-height to a Pango
Pango 1.50 introduces a line-height attribute. Use it.
This is enough to make line-height work for labels
and entries.
2021-08-22 15:15:50 -04:00
Matthias Clasen
d923402934 css: Add line-height property
This adds the plumbing to parse the line-height
property from CSS. Widgets are not picking it
up yet.
2021-08-22 15:15:50 -04:00
Benjamin Otte
9667f889b3 Merge branch 'clipboard-set-docs' into 'master'
docs: Expand gdk_clipboard_set() docs

See merge request GNOME/gtk!3865
2021-08-22 18:49:13 +00:00
Benjamin Otte
d2ea7af335 docs: Expand gdk_clipboard_set() docs 2021-08-22 18:49:12 +00:00
Matthias Clasen
f95e9407a9 Fix up test output for new version
Annoying that this test has to be touched every time
we bump the version.
2021-08-22 14:48:12 -04:00
Matthias Clasen
7be3c2974a windowhandle: Quiet a compiler warning
gesture was left uninitialized in the default case.
2021-08-22 14:19:14 -04:00
Matthias Clasen
5444f604cb Merge branch 'matthiasc/for-master' into 'master'
Bump version to 4.5

See merge request GNOME/gtk!3867
2021-08-22 17:53:34 +00:00
Matthias Clasen
94e68b0e36 Bump version to 4.5
4.4 has been branched off.
2021-08-22 13:06:29 -04:00
Matthias Clasen
910d86f958 NEWS: Updates 2021-08-22 13:06:15 -04:00
Matthias Clasen
fd885e42b0 Merge branch 'drop-gl' into 'master'
gsk: Drop the gl renderer

See merge request GNOME/gtk!3863
2021-08-22 17:04:25 +00:00
Matthias Clasen
ea31ae31c1 tests: Remove an outdated comment
It refers to a file that no longer exists.
2021-08-22 12:29:59 -04:00
Matthias Clasen
00763e5af3 media: Don't include gsk/gl/gskglrenderer.h 2021-08-22 12:29:40 -04:00
Matthias Clasen
1bf5aab18c testutils: Don't include gsk/gl/gskglrenderer.h 2021-08-22 12:29:13 -04:00
Matthias Clasen
210a709246 Merge branch 'matthiasc/for-master' into 'master'
Handle new pango attribute type

See merge request GNOME/gtk!3866
2021-08-22 15:22:14 +00:00
Matthias Clasen
5feba67a3d Handle new pango attribute type
Update all the places where we switch over
PangoAttrType to handle PANGO_ATTR_TEXT_TRANSFORM,
and do nothing for now - text-transform support
will land in 4.6.
2021-08-22 11:04:28 -04:00
Matthias Clasen
e9e373913e gsk: Drop the gl renderer
ngl supports all the same platforms as gl
now, and has seen more improvements in the
last cycle.
2021-08-20 22:58:30 -04:00
Matthias Clasen
f1f197e3b9 4.4.0 2021-08-20 15:10:25 -04:00
Matthias Clasen
cedb6183e9 Fix imcontext tests
We should force our internal im context for these
tests, so we don't depend on the environment.
2021-08-20 15:10:25 -04:00
Matthias Clasen
0415d46c0f Merge branch 'matthiasc/for-master' into 'master'
NEWS: Updates

See merge request GNOME/gtk!3861
2021-08-20 14:21:39 +00:00
Matthias Clasen
68388331c7 NEWS: Updates 2021-08-20 09:54:02 -04:00
Matthias Clasen
92817b0603 Merge branch 'cut-shortcut-activation-short' into 'master'
shortcutcontroller: Only do round-robin for mnemonics

Closes #4130

See merge request GNOME/gtk!3824
2021-08-20 13:50:51 +00:00
Matthias Clasen
f8a1726ffa shortcutcontroller: Only do round-robin for mnemonics
Don't do round-robin activation unless we are looking
for mnemonics, where this is an expected feature.

Fixes: #4130
2021-08-20 09:26:37 -04:00
Matthias Clasen
be34f27026 Merge branch 'matthiasc/for-master' into 'master'
gdk: Add a missing annotation

Closes #4097

See merge request GNOME/gtk!3860
2021-08-20 13:22:01 +00:00
Emmanuele Bassi
12c5518e2b Merge branch 'master' into 'master'
a11y: Send correct object reference for the root accessible

See merge request GNOME/gtk!3800
2021-08-20 13:18:37 +00:00
Matthias Clasen
d8ab5c3c45 gdk: Add a missing annotation
Mark an array as zero-terminated.

Fixes: #4097
2021-08-20 08:57:27 -04:00
Matthias Clasen
36d1c9e8b7 Merge branch 'add-support-for-windows-pointer-input-stack-gtk4' into 'master'
Add support for Windows Pointer Input Stack

Closes #262, #3162, #729, and #537

See merge request GNOME/gtk!3684
2021-08-20 11:31:16 +00:00
Matthias Clasen
45c047f5c0 Merge branch 'block-cursor-fixes' into 'master'
textview: Don't eat block cursors

See merge request GNOME/gtk!3857
2021-08-20 06:18:07 +00:00
Matthias Clasen
da1232caaf textview: Don't eat block cursors
We need to render even an empty paragraph when
it has a block cursor at the end. This fixes block
cursors not showing up in empty lines.
2021-08-20 01:57:31 -04:00
Matthias Clasen
fff5a83957 Merge branch 'matthiasc/for-master' into 'master'
window: Make resizeability changes work

See merge request GNOME/gtk!3856
2021-08-19 21:19:40 +00:00
Matthias Clasen
f5b6488eb2 window: Make resizeability changes work
We were forgetting to update the toplevel
properties here.
2021-08-19 16:03:58 -04:00
Luca Bacci
c02bae9e08 Move the _gdk_win32_pointer_input_api global variable into GdkWin32Display 2021-08-19 16:29:45 +02:00
Matthias Clasen
58e65ae7dd windows: Update the docs for env vars
We've replaced some env vars with a new one.
Update the docs to match.
2021-08-19 15:57:44 +02:00
Luca Bacci
3977518f00 Fix typo 2021-08-19 15:57:44 +02:00
Luca Bacci
8adee3dace Disable visual feedback for pen ad touch 2021-08-19 15:57:43 +02:00
Luca Bacci
09ad930da4 Filter out spurious mouse messages while handling pen or touch input 2021-08-19 15:57:43 +02:00
Luca Bacci
52f7bb6950 Add _gdk_win32_get_cursor_pos utility 2021-08-19 15:57:42 +02:00
Luca Bacci
68db945e47 Handle WinPointer input 2021-08-19 15:57:41 +02:00
Luca Bacci
b54f4cf5d4 Initialize WinPointer and enumerate devices 2021-08-19 15:57:41 +02:00
Luca Bacci
9a8a9451b1 Add new GdkDeviceWinpointer type 2021-08-19 15:57:40 +02:00
Luca Bacci
fffa903ce9 Add winpointer.h header file for type declarations 2021-08-19 15:57:39 +02:00
Luca Bacci
ab08885a32 Add entry for WinPointer in GdkWin32TabletInputAPI enum 2021-08-19 15:57:38 +02:00
Luca Bacci
ad3995b1b9 Make room for other API's than Wintab 2021-08-19 15:57:38 +02:00
Luca Bacci
75cc0710ac Remove _gdk_input_ignore_wintab variable
Also remove unused variable _gdk_max_colors
2021-08-19 15:57:37 +02:00
Luca Bacci
7cec7054e2 Rename some Wintab-related functions 2021-08-19 15:57:36 +02:00
Luca Bacci
fe280e578f Set active physical device when using the mouse 2021-08-19 15:57:36 +02:00
Luca Bacci
a32973f56b Move use of _gdk_win32_get_next_tick from synthesize_crossing_events to its callers 2021-08-19 15:57:35 +02:00
Luca Bacci
7762311911 Add a physical_device argument to send_crossing_event et al 2021-08-19 15:57:34 +02:00
Luca Bacci
edd73ffbed Raise _WIN32_WINNT macro to target Windows 7 API 2021-08-19 15:57:33 +02:00
Matthias Clasen
fca87d93e9 Updates 2021-08-19 01:47:43 -04:00
Matthias Clasen
c2fe2c0385 Merge branch 'better-word-selection' into 'master'
textview: Improve word selection

Closes #4177

See merge request GNOME/gtk!3855
2021-08-19 04:51:11 +00:00
Matthias Clasen
8aa25046dc textview: Improve word selection
Avoid selecting a whole extra paragraph when a select-by-words
selection is extended beyond the end of the previous paragraph.

Fixes: #4177
2021-08-19 00:33:03 -04:00
Matthias Clasen
27a07ed89c Merge branch 'matthiasc/for-master' into 'master'
Cosmetics

See merge request GNOME/gtk!3854
2021-08-19 02:49:23 +00:00
Matthias Clasen
071a6bcc06 Cosmetics 2021-08-18 22:33:23 -04:00
Benjamin Otte
f98ac6590d Merge branch 'wip/otte/for-master' into 'master'
demo: Add a dnd special-case for textures

See merge request GNOME/gtk!3853
2021-08-19 01:42:26 +00:00
Benjamin Otte
6b733d2943 gtk-demo: Make clipboard demo paste from clipboard
The old code was just pasting local clipboard data that we put there
ourselves and was causing criticals on remote clipboard data. Now the
code does the proper async paste.
2021-08-19 03:16:48 +02:00
Benjamin Otte
6f165efcdb contentprovider: Switch wrong order in type check
We can provide textures as a paintable - we can't provide paintables as
textures.
2021-08-19 03:16:48 +02:00
Benjamin Otte
7bc1c9a562 demo: Add a dnd special-case for textures
If the DND/clipboard machinery knows a texture is a texture, it will try
to serialize it. Paintables can't be serialized, so it wouldn't try.
2021-08-19 03:16:48 +02:00
Matthias Clasen
1596fdeba3 Merge branch 'matthiasc/for-master' into 'master'
infobar: Update buildable docs

Closes #4164

See merge request GNOME/gtk!3852
2021-08-18 22:05:07 +00:00
Matthias Clasen
1599b659cf infobar: Update buildable docs
Document the current state of GtkBuilder support in
GtkInfoBar, not what we had in GTK3.

Fixes: #4164
2021-08-18 17:42:54 -04:00
Matthias Clasen
bb65564c7d Merge branch 'seat-v7' into 'master'
gdk/wayland: add support for wl_seat version 7

See merge request GNOME/gtk!3842
2021-08-18 21:10:30 +00:00
Matthias Clasen
03031b3dc1 Merge branch 'fix/wm_class2' into 'master'
x11: ensure WM class is not null even if display is initialized early

See merge request GNOME/gtk!3808
2021-08-18 18:24:37 +00:00
Benjamin Otte
b7636ebbc0 Merge branch 'win32-drop-local-dnd' into 'master'
gdk/win32: Drop local DnD protocol

See merge request GNOME/gtk!3830
2021-08-18 14:27:14 +00:00
Matthias Clasen
5707b80a69 Merge branch 'win32-check-shader-support' into 'master'
GDK-Win32: Reject GL context if shaders aren't supported (fix issue #4165)

Closes #4165

See merge request GNOME/gtk!3850
2021-08-18 12:19:57 +00:00
Matthias Clasen
81e5d4c327 Merge branch 'master' into 'master'
gtkbuilderparser: Fix duplicate object id detection

See merge request GNOME/gtk!3848
2021-08-18 12:00:41 +00:00
Ye Moran
f8111125ef gtkbuilderparser: Fix duplicate object id detection 2021-08-18 12:00:40 +00:00
Matthias Clasen
c020e83890 Merge branch 'matthiasc/for-master' into 'master'
Add a custom input test

See merge request GNOME/gtk!3851
2021-08-18 03:24:41 +00:00
Matthias Clasen
f6659fea8d imcontext: Improve docs
Add some more docs around GtkIMContext.
2021-08-17 22:33:26 -04:00
Matthias Clasen
a06858ccd9 Add a custom input test
This shows the minimal work required to hook up an
im context to a custom widget.
2021-08-17 22:33:26 -04:00
Emmanuele Bassi
c6c48d327c Merge branch 'wip/exalm/query-action-transfer' into 'master'
widget: Fix gtk_widget_class_query_action() annotations

See merge request GNOME/gtk!3843
2021-08-17 17:56:40 +00:00
Chun-wei Fan
5d0f188615 GDK-Win32: Reject WGL context if shaders aren't supported
When we initialize OpenGL, check whether we have OpenGL  2.0 or later; if not,
check whether we have the 'GL_ARB_shader_objects' extension, since we must be
able to support shaders if using OpenGL for GTK.

If we don't support shaders, as some Windows graphics drivers do not support
OpenGL adequately, notably older Intel drivers, reject and destroy the GL
context that we created, and so fallback to the Cairo GSK renderer, so that
things continue to run, albeit with an expected warning message that the GL
context cannot be realized.

Also, when we could not make the created dummy WGL context current during
initialization, make sure that we destroy the dummy WGL context as well.

Fixes issue #4165.
2021-08-17 16:25:09 +08:00
Benjamin Otte
78fcc8feb8 Merge branch 'wip/otte/for-master' into 'master'
gdk: Include Vulkan error code in vulkan_strerror()

See merge request GNOME/gtk!3844
2021-08-12 12:36:28 +00:00
Benjamin Otte
27cad85247 gdk: Include Vulkan error code in vulkan_strerror() 2021-08-12 14:19:30 +02:00
Simon Ser
ad0c1d4dbe gdk/wayland: add support for wl_seat version 7
Version 7 requires wl_keyboard keymaps to be mapped with
MAP_PRIVATE, so that the compositor can share the same keymap
file between multiple clients.
2021-08-11 16:37:03 +02:00
Simon Ser
00abaed89a gdk/wayland: add support for wl_seat version 6
Version 6 adds two new wl_touch events, which can be ignored.
2021-08-11 16:36:57 +02:00
Alexander Mikhaylenko
342f02711b widget: Fix gtk_widget_class_query_action() annotations
Add transfer none on all out values as they aren't being copied.
2021-08-11 14:33:38 +05:00
Matthias Clasen
d9c48a8d01 Merge branch 'matthiasc/for-master' into 'master'
Handle the new line height pango attribute

See merge request GNOME/gtk!3840
2021-08-10 15:08:20 +00:00
Matthias Clasen
d757696116 ci: Add libjpeg-turbo-devel to the Fedora image
This was getting downloaded from sourceforge every
time for the docs build, and that started failing.
2021-08-10 08:22:52 -04:00
Matthias Clasen
528ebfabf0 Handle the new line height pango attribute
Update all the places where we switch over PangoAttributeType
to handle (and ignore, for now) the new line height attribute.
2021-08-10 08:22:52 -04:00
Vincent Bernat
2ebde276d1 x11: ensure WM class is not null even if display is initialized early
With gtkmm, when using `Application()`, the display is initialized
before we know the application name and therefore, the program class
associated to the display is NULL.

Instead of providing a default value, we set it equal to program name
when NULL. Moreover, we give up on capitalizing the class name to keep
the code super simple. Also, not using a capitalized name is
consistent with `gdk_x11_display_open()`. If someone has a good reason
to use a capitalized name, here is how to do it.

```c
  class_hint = XAllocClassHint ();
  class_hint->res_name = (char *) g_get_prgname ();
  if (display_x11->program_class)
    {
      class_hint->res_class = (char *) g_strdup (display_x11->program_class);
    }
  else if (class_hint->res_name && class_hint->res_name[0])
    {
      class_hint->res_class = (char *) g_strdup (class_hint->res_name);
      class_hint->res_class[0] = g_ascii_toupper (class_hint->res_class[0]);
    }
  XSetClassHint (xdisplay, impl->xid, class_hint);
  g_free (class_hint->res_class);
  XFree (class_hint);
```

Fix eff53c023a ("x11: set a default value for program_class")
2021-08-10 09:14:36 +02:00
Matthias Clasen
04f3c8054b Merge branch 'callback-annotation-again' into 'master'
widget: Change callback scope

See merge request GNOME/gtk!3796
2021-08-10 01:16:56 +00:00
Benjamin Otte
ea07bf7536 Merge branch 'wip/otte/for-master' into 'master'
ngl: Make current when unrealizing

See merge request GNOME/gtk!3835
2021-08-08 01:09:31 +00:00
Benjamin Otte
80e6f1ca8c ngl: Make current when unrealizing
The profiler (at least) discards GL objects and we want to discard them
on the right context.
2021-08-08 02:17:08 +02:00
Matthias Clasen
54d29568ec Merge branch 'matthiasc/for-master' into 'master'
Cosmetics: Tweak css parser error messages

See merge request GNOME/gtk!3834
2021-08-07 22:48:32 +00:00
Matthias Clasen
4e1ea58503 Cosmetics: Tweak css parser error messages
These show up in tooltips, so they should a) be capitalized
and b) not end with a period.
2021-08-07 18:18:10 -04:00
Andre Klapper
90c429a91c Belarusian translation: Remove broken translation string 2021-08-07 19:10:23 +02:00
Andre Klapper
4b28e038e0 Khmer translation: Strip some invisible bytes from setting translations 2021-08-07 19:10:22 +02:00
Matthias Clasen
8df694a358 Merge branch 'matthiasc/for-master' into 'master'
gtk-demo: Spruce up the hypertext demo

See merge request GNOME/gtk!3832
2021-08-07 16:56:56 +00:00
Yaron Shahrabani
eb8778e1cd Update Hebrew translation
(cherry picked from commit 11e6ce1751)
2021-08-07 16:51:55 +00:00
Matthias Clasen
256f3a0d60 gtk-demo: Spruce up the hypertext demo
Use the newish allow-breaks pango attribute
to make the text break better.
2021-08-07 12:35:17 -04:00
Danial Behzadi
54c087e7ec Update Persian translation 2021-08-07 14:48:55 +00:00
Danial Behzadi
69a99b89f9 Update Persian translation
(cherry picked from commit b467881274)
2021-08-07 14:45:02 +00:00
Matthias Clasen
f328ab9d83 Merge branch 'wip/chergert/revert-top-margin' into 'master'
Revert "textview: fix yoffset position when top_margin is set"

See merge request GNOME/gtk!3828
2021-08-06 13:13:21 +00:00
Chun-wei Fan
8acce5f294 gdk/win32: Drop local DnD protocol
It is basically not used by default and is pretty much broken at this point, so
it's about time to drop it.

Let's focus on fixing the OLE2 DnD protocol.
2021-08-06 17:16:27 +08:00
Matthias Clasen
bdbe0acd1f Merge branch 'matthiasc/for-master' into 'master'
settings: Default gtk-split-cursor to FALSE

See merge request GNOME/gtk!3827
2021-08-05 19:17:54 +00:00
Christian Hergert
fc701baef8 Revert "textview: fix yoffset position when top_margin is set"
This reverts commit 908b1e5e12.

This commit broke top-margin altogether.
2021-08-05 11:52:45 -07:00
Matthias Clasen
a457a81fd9 Merge branch 'matthiasc/for-master' into 'master'
text: Move setup code out of a loop

See merge request GNOME/gtk!3826
2021-08-05 18:45:39 +00:00
Matthias Clasen
4cc7977d36 settings: Default gtk-split-cursor to FALSE
According to Owen, this was the intention when the setting
was added in 2001. It only took us 20 years to fix the
default value.
2021-08-05 14:05:28 -04:00
Matthias Clasen
e5e7f5dd88 ci: Disable treeview-headers-hidden reftest
Somebody needs to figure out why it fails in ci so
frequently.
2021-08-05 12:41:04 -04:00
Matthias Clasen
916886312a Merge branch 'wip/exalm/shadow-extents' into 'master'
Shrink shadow extents

See merge request GNOME/gtk!3825
2021-08-05 16:39:52 +00:00
Matthias Clasen
8ff94ea1f2 text: Move setup code out of a loop
Just a cleanup, no functional change.
2021-08-05 12:31:18 -04:00
Matthias Clasen
053bd0cd31 Merge branch 'fix-tab-not-captured-in-popover' into 'master'
popovermenu: Cycle around focus also with (Shift+)Tab

Closes #3915

See merge request GNOME/gtk!3732
2021-08-05 02:07:43 +00:00
vanadiae
a3ce574193 popover: Cycle around focus with (Shift+)Tab
Same thing as the previous popovermenu commit, except for the base popover
because the popovermenu needs special behaviour with e.g. sides arrow so
we need to have the "cycle around" for regular popovers here too.
2021-08-04 12:11:44 +02:00
vanadiae
ef92adc87d popovermenu: Cycle around focus also with (Shift+)Tab
Currently when moving the focus with (Shift+)Tab, it also traverses the window's
widgets, although it would be expected that the focus stays within the popover,
as it's (almost) like it's a separate window. This would be consistent with
the behaviour of the Up/down arrows, which do cycle around the focus once it
reaches the end.

So this commit makes the popovermenu cycle around focus in any direction, apart
from left/right because they are used to open and close submenus and it wouldn't
make sense anyway to cycle horizontally as there's usually only one widget per
line.
2021-08-04 12:11:44 +02:00
Alexander Mikhaylenko
46a9538b6a Shrink shadow extents
Long time ago, Cairo shadows in both GTK3 and 4 were drawn at a size about
twice their radius. Eventually this was fixed but the shadow extents are
still calculated for the previous size and appear unreasonably large: for
example, 141px for a 50px radius shadow. This can get very noticeable in
places such as invisible window frame which gets included into screenshots.

https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/3419 just divides the
radius by 2 when drawing a shadow with Cairo, do the same when calculating
extents.

See https://gitlab.gnome.org/GNOME/gtk/-/issues/3841
2021-08-04 14:47:17 +05:00
Matthias Clasen
ca547b8716 Merge branch 'combobox-keynav' into 'master'
treepopover: Add keynav

See merge request GNOME/gtk!3822
2021-08-03 11:20:56 +00:00
Matthias Clasen
04ea51e843 treepopover: Start adding keynav
Arrange for the items to be focusable, and add keyboard
activation. Still missing: cycling focus inside the
popover.
2021-08-02 23:49:05 -04:00
Matthias Clasen
f7dc0dda4e Merge branch 'big-keysyms' into 'master'
imcontext: Treat keysyms as 32bit values

Closes #4149

See merge request GNOME/gtk!3819
2021-08-03 01:05:16 +00:00
Matthias Clasen
8713843022 Merge branch 'surround-test' into 'master'
Remove an unimplemented function

Closes #4151

See merge request GNOME/gtk!3820
2021-08-03 01:00:13 +00:00
Matthias Clasen
6563b05d60 Add some GtkIMContext tests
For now, these check that the surrounding handling
in GtkText and GtkTextView is sane.

Fixes: #4151
2021-08-02 20:44:40 -04:00
Matthias Clasen
d119c55b72 textview: Fix the get_surrounding implementation
This was, sadly, returning garbage.
2021-08-02 20:44:40 -04:00
Matthias Clasen
253e25a73c Add a private getter for the textview key controller
This will be used in tests.
2021-08-02 20:44:40 -04:00
Matthias Clasen
c63774967f Remove an unimplemented function
_gtk_entry_get_im_context does not exist.
2021-08-02 20:44:40 -04:00
Matthias Clasen
bbc36448fb imcontext: Treat keysyms as 32bit values
Our compose table format is still limited to 16bit
values for keysyms, but what we see in key events
can be 32bit values, and we treat them as such now.

Fixes: #4149
2021-08-02 19:16:18 -04:00
Matthias Clasen
5df323fb64 Merge branch 'fix-custom-widget-menu-focus' into 'master'
menusectionbox: Passthrough the focus function of custom widgets' gizmo

Closes gnome-text-editor#93

See merge request GNOME/gtk!3817
2021-08-02 22:21:08 +00:00
Matthias Clasen
0f2c5f13be Merge branch 'wip/otte/for-master' into 'master'
video: Use cross-fade transition to avoid resizes

See merge request GNOME/gtk!3815
2021-08-02 22:19:39 +00:00
Matthias Clasen
58180ad3be Merge branch 'fix-4144' into 'master'
gtkgesturerotate: Fix assertion

Closes #4144

See merge request GNOME/gtk!3818
2021-08-02 22:17:20 +00:00
James Westman
fb0229890b gtkgesturerotate: Fix assertion
Fixes #4144. An assertion would be printed when GtkGestureRotate was
used with a touchscreen.
2021-08-02 16:38:35 -05:00
vanadiae
9099888398 menusectionbox: Passthrough the focus function of custom widgets' gizmo
It broke keyboard focusing any widget added through the custom widget
menu feature. So for example if you put e.g. a custom check box widget
in a menu, you won't be able to focus it.

This is because the gizmo is mostly used to custom drawing with e.g.
CSS for small visual elements like scale markers. That's probably why
gizmo's default focus overrides block the focus from going through
the children. So this commit fixes it by overriding those and passing
the focus through the children.
2021-08-02 21:20:32 +02:00
Benjamin Otte
882855f865 video: Use cross-fade transition to avoid resizes
Slide animations cause changes in the size requests due to the
behavior of GtkRevealer. We can avoid those by using cross-fades, which
don't have that problem.

Besides, cross-fades look better anyway.
2021-08-02 20:11:32 +02:00
Matthias Clasen
f59d2ae89d Merge branch 'input-tweaks' into 'master'
imcontext: Tweak Compose sequence preedit

Closes #10, #4127, and #4124

See merge request GNOME/gtk!3799
2021-08-02 18:07:46 +00:00
Matthias Clasen
7c3a53a171 Merge branch 'fix-double-underscore-mnemonic' into 'master'
label: Ignore __ for mnemonics

Closes #4129

See merge request GNOME/gtk!3814
2021-08-02 03:54:29 +00:00
Matthias Clasen
1e22572716 Avoid pango deprecations
This function has been deprecated on the main
branch of pango. Since we don't want to bump our
pango dependency to 1.49 yet, ignore the deprecation.
2021-08-01 23:20:01 -04:00
Matthias Clasen
8a25f54e1f Add more label parsing tests
Test various combinations of underline and markup
parsing.
2021-08-01 23:19:00 -04:00
Matthias Clasen
c51f2fc0ec label: Ignore __ for mnemonics
We were not ignoring double underscores for mnemonics
in one place, as we should.

Fixes: #4129
2021-08-01 22:14:12 -04:00
Matthias Clasen
2a528df977 Merge branch 'titlebar-gesture' into 'master'
Delegate titlebar action to the compositor if possible

See merge request GNOME/gtk!3797
2021-08-02 01:14:08 +00:00
Piotr Drąg
84684bd56e Update Polish translation 2021-08-01 14:21:25 +02:00
Matthias Clasen
e1606ce8eb Merge branch 'color-glyph-fixes' into 'master'
gsk: Make color glyphs

Closes #4141

See merge request GNOME/gtk!3812
2021-07-31 20:54:39 +00:00
Matthias Clasen
47072e0441 Merge branch 'fix-iconhelper' into 'master'
iconhelper: Fix the paintable implementation

Closes #4140

See merge request GNOME/gtk!3809
2021-07-31 20:35:08 +00:00
Matthias Clasen
915c229396 gsk: Use harfbuzz for color fonts
harfbuzz has all the information we need, so we
can avoid poking directly at freetype apis. Also
drop the caching of color glyph information until
it turns out to be a problem.
2021-07-31 16:34:38 -04:00
Matthias Clasen
0bf46b4845 Bump the harfbuzz dep
We need 2.1.0, which has the hb_ot_color apis that we
are going to use in the next commit.
2021-07-31 16:34:38 -04:00
Matthias Clasen
a7a2dbc3ea gsk: Cache per-glyph color information
We don't really want to load the bitmaps every time
we create a render node, so do it once and cache the
information on the PangoFont.
2021-07-31 16:34:38 -04:00
Matthias Clasen
7e8f586859 ngl: Use per-glyph color information
Decide per-glyph whether we need color nor not.

Fixes: #4141
2021-07-31 16:34:24 -04:00
Matthias Clasen
bb9dccd773 gsk: Mark color glyphs
Steal a bit from PangoGlyphVisAttr to mark glyphs
that have color.
2021-07-31 16:34:24 -04:00
Emmanuele Bassi
7b743e662e Merge branch 'update-docs' into 'master'
docs: Update the URL for related documentation

See merge request GNOME/gtk!3813
2021-07-31 18:39:52 +00:00
Emmanuele Bassi
769dc53c05 docs: Update the URLs of related projects for GTK
And install the gi-docgen project file as well.
2021-07-31 19:08:34 +01:00
Emmanuele Bassi
1a4554daf3 docs: Update the URLs of related projects for GSK
And install the gi-docgen project file.
2021-07-31 19:07:18 +01:00
Emmanuele Bassi
6c0633ef61 docs: Update the URL for related documentation
And install the gi-docgen project files for GDK.
2021-07-31 19:05:33 +01:00
Emmanuele Bassi
4d020a3875 Merge branch 'docs-trigger' into 'master'
ci: Trigger a pages build

See merge request GNOME/gtk!3811
2021-07-31 17:16:26 +00:00
Emmanuele Bassi
316cc55e69 ci: Trigger a pages build
Do not publish the API reference directly, but trigger a CI pipeline for
the docs-gtk-org branch, which will then do the publishing.
2021-07-31 17:13:27 +01:00
Emmanuele Bassi
95f2634ea9 Merge branch 'iter-is-valid-docs' into 'master'
docs: Fix iter_is_valid() description

See merge request GNOME/gtk!3810
2021-07-31 13:07:07 +00:00
Emmanuele Bassi
95c032f531 docs: Fix iter_is_valid() description
Drop the "WARNING" and the block quote, and follow the existing
documentation style guidelines.
2021-07-31 13:41:13 +01:00
Matthias Clasen
744955753f iconhelper: Fix the paintable implementation
get_current_image was recursing due to an obvious typo.

Fixes: #4140
2021-07-31 08:27:17 -04:00
Matthias Clasen
ae5e7dc65d Merge branch 'glyph-cache-mystery' into 'master'
ngl: Bypass pango for glyph cache rendering

See merge request GNOME/gtk!3807
2021-07-31 00:38:41 +00:00
Matthias Clasen
ed41c46926 ngl: Bypass pango for glyph cache rendering
We can just use cairo directly here,
and cut out some layers of pango in the middle.
2021-07-30 19:46:07 -04:00
Matthias Clasen
a460fb2734 Merge branch 'check-activate' into 'master'
checkbutton: Some fixes when used with GActions

See merge request GNOME/gtk!3805
2021-07-30 23:39:17 +00:00
Matthias Clasen
39ddce6ba3 Merge branch 'fix/wm_class' into 'master'
x11: set a default value for program_class

Closes #4138

See merge request GNOME/gtk!3806
2021-07-30 23:25:08 +00:00
Matthias Clasen
8da7e3bdc3 Merge branch 'wip/otte/for-master' into 'master'
widget-factory: Expand the video to cover the whole frame

See merge request GNOME/gtk!3804
2021-07-30 22:43:29 +00:00
Vincent Bernat
eff53c023a x11: set a default value for program_class
This was also the behaviour with GTK 3. We use the capitalized program
name.

Fixes #4138

Signed-off-by: Vincent Bernat <vincent@bernat.ch>
2021-07-30 23:22:32 +02:00
Benjamin Otte
99e4a6a2d6 widget-factory: Propagate natural size for text styles
This avoids them requiring scrolling.
2021-07-30 20:54:58 +02:00
Benjamin Otte
c06817b951 widget-factory: Make frames cooler
Instead of havoing a label for the video frame that clashes with the
background of the video, add a frame around the text styles box and add
a label for them. As a side benefit, it also makes it more obvious that
it is scrollable.

Note: Most of this patch is just reindenting.
2021-07-30 20:43:02 +02:00
Benjamin Otte
e765aaa3f4 widget-factory: Expand the video to cover the whole frame
1. This looks way cooler.

2. Since the frame is rounded, it adds a very visible test for our
   clipping of rounded rectangles.
2021-07-30 20:37:34 +02:00
Florian Müllner
1728aa581c checkbutton: Activate when moving focus
Currently we update the :active property on both the previous and
new focus button. That "visually activate" the button and will
emit ::toggled, but if the button is associated with an action,
the action state won't change.

Fix that by activating the new focus instead of explicitly fiddling
with the :active property.
2021-07-30 20:34:24 +02:00
Florian Müllner
c50475de34 checkbutton: Delegate ::activate to the helper if appropriate
If the button is associated with an action, the action is currently
only activated when the button is clicked, not when it is activated.
2021-07-30 20:34:24 +02:00
Mike Gorse
5d7ecb7a6e a11y: Remove unneeded check 2021-07-30 08:58:27 -05:00
Matthias Clasen
06348a8517 Merge branch 'wip/chergert/fix-4134' into 'master'
textview: fix yoffset position when top_margin is set

Closes #4134

See merge request GNOME/gtk!3801
2021-07-30 13:41:30 +00:00
Matthias Clasen
c4dbb8f01e imcontext: Code cleanup 2021-07-29 20:37:58 -04:00
Matthias Clasen
e67b2cb54b composetable: Allow multiple dead keys
Remove the limitation on the number of dead keys
that we match, and allow the result be be multiple
characters.

Regenerate the builtin sequences, since this changes
what dead key sequences we can reproduce algorithmically.

Update tests to match.

Fixes: #10
2021-07-29 20:37:30 -04:00
Christian Hergert
908b1e5e12 textview: fix yoffset position when top_margin is set
This doesn't need to be included in the calculation or it will cause the
yoffset to continually shift while the window is resized.

Fixes #4134
2021-07-29 16:45:04 -07:00
Matthias Clasen
539391ce6c composetable: Change an API
Make gtk_check_algorithmically take a GString
for the result. This is in preparation for allowing
multi-character results here, in the future.

Update all callers.
2021-07-29 17:29:25 -04:00
Mike Gorse
7fc90aed26 a11y: Send correct object reference for the root accessible 2021-07-29 15:55:58 -05:00
Florian Müllner
23e79d2eb2 gtk/windowhandle: Delegate titlebar action to the compositor if possible
Delegating the action to the compositor not only improves consistency
with server-side decorations, but also allows for actions that aren't
available client-side (like lower-in-middle-click).

https://gitlab.gnome.org/GNOME/mutter/-/issues/602
2021-07-29 21:39:32 +02:00
Florian Müllner
0c7b1431d7 gdk/toplevel: Add gdk_toplevel_titlebar_gesture()
Where supported, this allows delegating the titlebar action to the
compositor instead of trying to replicate its behavior client-side.

https://gitlab.gnome.org/GNOME/mutter/-/issues/602
2021-07-29 21:39:32 +02:00
Matthias Clasen
b6c0155836 imcontext: Handle Escape in Compose sequence
Treat Escape the same in hex sequences and in
Compose sequence: reset the state.
2021-07-29 08:39:17 -04:00
Matthias Clasen
76d67b586c imcontext: Tweak Compose sequence handling
When we don't have any matches for a Compose sequence
anymore, beep, and keep the preedit as it was for the
last match.

Fixes: #4127
2021-07-29 08:24:14 -04:00
Matthias Clasen
914edb1472 composetable: Add a prefix api
Add a function that computes the longest prefix
of a buffer for which a compose table has matches.
2021-07-29 08:23:40 -04:00
Matthias Clasen
dbf5033f94 composetable: Reduce the scope of a variable
'prefix' is not a good name for a file-scope variable,
move it into the sole function using it.
2021-07-29 08:22:52 -04:00
Matthias Clasen
cc6ecc8b62 Merge branch 'source-static-name' into 'master'
Avoid copying static debug strings

See merge request GNOME/gtk!3789
2021-07-29 11:59:02 +00:00
Matthias Clasen
b7e6922605 imcontext: Tweak Compose sequence preedit
When sequences contain multiple Compose keys,
don't hide the first one. This is a very fringe
case, but it matches the behavior of IBus.

Fixes: #4124
2021-07-29 07:36:48 -04:00
Matthias Clasen
05eaffb9f2 ci: Collect tools test output
This should help understanding why some of them fail.
2021-07-28 22:42:46 -04:00
Matthias Clasen
67b568f464 testsuite: Set TEST_RESULT_DIR for tools tests 2021-07-28 22:42:46 -04:00
Matthias Clasen
19b534f7de Avoid copying static debug strings
The g_source_set_name calls were showing up as a
major source of strdups in our profiles. Avoid that
by using new GLib api when available.
2021-07-28 22:42:46 -04:00
Florian Müllner
bc386c9a60 widget: Change callback scope
Look who changed his mind since commit 8e2ffb3b46 :-)

The "call" scope means that the callback is only used during the
function call itself (here: gtk_widget_class_install_action()).

That's clearly wrong here, as the callback is invoked every time
the action is activated.

Arguably the "notified" scope is a better match here, where the
lack of a GDestroyNotify parameter suggests that the callback may
be used forever (which is the case here).

Related: #3498
2021-07-28 21:48:01 +02:00
Matthias Clasen
db8b3419c2 Merge branch 'compose-parse-msvc' into 'master'
compose-parse.c: Include stdlib.h (fix build on Visual Studio)

See merge request GNOME/gtk!3794
2021-07-28 10:38:25 +00:00
Fabio Tomat
0f5ba5192a Update Friulian translation
(cherry picked from commit 16aa8dbad7)
2021-07-28 09:11:33 +00:00
Chun-wei Fan
108c423d70 compose-parse.c: Include stdlib.h
That is needed for exit(), and it may not have been included by the
other headers.
2021-07-28 15:18:36 +08:00
Emmanuele Bassi
dded10a396 Merge branch 'gi-fix' into 'master'
gdk: add missing Since annotation

See merge request GNOME/gtk!3790
2021-07-27 17:38:28 +00:00
Marc-André Lureau
1b080826db gdk: add missing Since annotation
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-07-27 21:01:31 +04:00
Matthias Clasen
910f23ea19 Merge branch 'wip/otte/widgetfactory-dnd' into 'master'
Improve DND

See merge request GNOME/gtk!3785
2021-07-27 04:12:58 +00:00
Benjamin Otte
f1b50baba1 widget-factory: Add images that support dnd
Just use the bottom left notebook for a GtkPicture with custom drag
source and drop target.
2021-07-27 04:40:57 +02:00
Matthias Clasen
4453597946 widget-factory: Some new backgrounds
Snowy wasn't ideal because of the aspect ratio.
Replace it by beach and nyc.
2021-07-27 04:40:42 +02:00
Benjamin Otte
192bfa10cb droptarget: Make formats construct-only writable
This way, it can be set in GtkBuilder.

Also make sure to only ever look at the GTypes set in the formats, as
GtkDropTarget cannot deal with mime types.
2021-07-27 04:28:04 +02:00
Benjamin Otte
0781429dc5 builder: Add support for GdkContentFormats 2021-07-27 04:28:04 +02:00
Benjamin Otte
d760332f00 testsuite: Add contentformat tests 2021-07-27 04:28:04 +02:00
Benjamin Otte
131be5f2e8 contentformats: Add gdk_content_formats_parse() 2021-07-27 04:13:42 +02:00
Matthias Clasen
57a95c540c Merge branch 'matthiasc/for-master' into 'master'
ngl: Cosmetics

See merge request GNOME/gtk!3786
2021-07-26 18:21:56 +00:00
Matthias Clasen
09deb1d757 ngl: Cosmetics
Use the macro we already have to check that colors
are fully transparent.
2021-07-26 13:42:10 -04:00
Matthias Clasen
5c4aba4b9c Merge branch 'wip/compose-parser' into 'master'
Clean up the GtkComposeTable api

See merge request GNOME/gtk!3746
2021-07-26 11:51:14 +00:00
Benjamin Otte
6a5d555f58 contentformats: Change the format of gdk_content_formats_to_string()
Now, we just print a whitespace-separated list of GTypes and mime types.

This makes this neat for 2 things:

1. Parsing it (see next commit)
2. Using it in GtkBuilder (see commits after that)

In particular, the common case of supporting a single GType (or mime
type) looks like just printing the GType (or mime type), which in
GtkBuilder looks like
<property name="formats">GdkTexture</property>
2021-07-26 02:28:49 +02:00
Benjamin Otte
f5dc71021f dnd: Guard drags with a reference when finishing
Usually the "dnd-finished" signal will be used to unref the GdkDrag. In
those cases, we would lose the object, so that when we do the final
drag_drop_done() afterwards, we wouldn't have a remaining reference.

With the reference guard, this now works.
2021-07-26 02:18:54 +02:00
Matthias Clasen
39005461c5 4.3.2 2021-07-24 22:04:49 -04:00
Matthias Clasen
4dc4c00267 Merge branch 'misc-speedups' into 'master'
ngl: Speed up clipping calculations a bit

See merge request GNOME/gtk!3784
2021-07-25 02:03:46 +00:00
Matthias Clasen
d76460343a sizerequest: Simplify some code
Avoid some repeated MAX().
2021-07-24 18:49:41 -04:00
Matthias Clasen
0d8dd0c664 sizerequest: Keep branches in sync
There are some unintentional differences between
the path that uses a layout manager, and the path
that uses widget vfuncs. Sync them up.
2021-07-24 18:49:41 -04:00
Matthias Clasen
ee6491f717 widget: Avoid some unnecessary back-and-forth casting
Avoid some unnecessary casting and a redundant early exit.
2021-07-24 18:49:27 -04:00
Matthias Clasen
7044951dab widget: Avoid GObject data for action muxer
Most widget have an action muxer now, so just
store it in GtkWidgetPrivate.
2021-07-24 18:48:10 -04:00
Matthias Clasen
98986a25f9 layoutmanager: Avoid some overhead
Use inline getters for some things.
2021-07-24 18:48:10 -04:00
Matthias Clasen
ae3e586714 gridlayout: Avoid some unnecessary overhead
Use inline functions for some things.
2021-07-24 18:48:10 -04:00
Matthias Clasen
0ef12193f9 gsk: Optimize gsk_transform_to...
Optimize these functions for the common cases.
2021-07-24 18:48:10 -04:00
Matthias Clasen
b695ef9168 gsk: Add a shortcut for a common transform case
Add a private getter for the translation part of a
transform node, to avoid pulling it out of the transform
over and over.
2021-07-24 18:48:09 -04:00
Matthias Clasen
7fb1389648 gsk: Add a private getter for container children
No need to get them one-by-one, in our inner loop.
2021-07-24 18:48:09 -04:00
Matthias Clasen
f88efb811b ngl: Reduce type checking overhead
No need to be very careful here, these are entirely
internal types.
2021-07-24 18:48:09 -04:00
Matthias Clasen
466d33ca69 ngl: Speed up clipping calculations a bit
Exit as early as possible from intersect_rounded_rectilinear.
2021-07-24 18:48:09 -04:00
Piotr Drąg
d44ce1987d Update POTFILES.in 2021-07-24 14:38:51 +02:00
Emmanuele Bassi
527b2c5ab1 Merge branch 'no-pposition' into 'master'
gdk/x11: Do not set PPosition hint

See merge request GNOME/gtk!3781
2021-07-24 11:45:00 +00:00
Florian Müllner
4d0c2997cf gdk/x11: Do not set PPosition hint
It is good practice for (floating) window managers to respect explicit
position hints from clients (as long as the window wouldn't end up
off-screen etc.).

Before commit 13d3afa56e, GTK had a flag for setting the PPosition hint,
but now does so unconditionally. However the real intention is to *not*
request a fixed position, so don't do that.
2021-07-24 06:32:16 +02:00
Matthias Clasen
6f04ec9dae Merge branch 'wip/exalm/gtktext-selection-fix' into 'master'
text: Use the widget y coordinate for gestures

See merge request GNOME/gtk!3780
2021-07-23 20:29:07 +00:00
Alexander Mikhaylenko
00cc99818d text: Use the widget y coordinate for gestures
Currently we use layout coordinates and widget height when determining
where a click or drag has happened. If the widget has top padding (which it
does inside a GtkEntry, for example), the area where it's possible to select
text is shifted down, so the part of GtkText above the layout is not counted
as the draggable area and instead the equal area below the widget is counted.

Since GtkText is always single-line, there's no need to do any of that and
we can use widget coordinates. Then the draggable area matches the widget
and the problems goes away.
2021-07-23 23:37:36 +05:00
Matthias Clasen
e51fdc1c9b Merge branch 'stack-page-name' into 'master'
stack: GtkStackPage:name is not construct-only

Closes #4109

See merge request GNOME/gtk!3778
2021-07-23 14:25:29 +00:00
Matthias Clasen
8d5ef4ab30 Merge branch 'matthiasc/for-master' into 'master'
Cosmetics

See merge request GNOME/gtk!3779
2021-07-22 21:22:55 +00:00
Matthias Clasen
7bdda15b86 Cosmetics
Fix a comment typo.
2021-07-22 17:03:08 -04:00
Matthias Clasen
4c41ef8de3 stack: GtkStackPage:name is not construct-only
We have a setter for this property, so we clearly
weren't serious when we marked it as construct-only.

Fixes: #4109
2021-07-22 16:55:15 -04:00
Matthias Clasen
7aec3b0fa1 Merge branch 'startup-profiling' into 'master'
Add more sysprof marks

See merge request GNOME/gtk!3777
2021-07-22 19:20:22 +00:00
Matthias Clasen
fce23c981b Add more sysprof marks
Add a few more marks during gtk_init to figure out where
our startup time goes, and avoid the sysprof initialization
from distorting the first mark.
2021-07-22 14:47:02 -04:00
Matthias Clasen
351819b570 Merge branch 'startup-profiling' into 'master'
Add more sysprof marks

See merge request GNOME/gtk!3776
2021-07-22 17:04:27 +00:00
Matthias Clasen
a10b1b7341 Add more sysprof marks
Add a few more marks during gtk_init to figure out where
our startup time goes, and avoid the sysprof initialization
from distorting the first mark.
2021-07-22 12:51:32 -04:00
Benjamin Otte
02c6226741 Merge branch 'wip/otte/gleanup' into 'master'
reorganize GDK's GL code

See merge request GNOME/gtk!3726
2021-07-22 14:51:05 +00:00
Benjamin Otte
620ccdabb5 glx: Get rid fo DrawableInfo
Store the frame counter in the surface, where it belongs.
2021-07-22 16:28:16 +02:00
Chun-wei Fan
4b12dc6547 gdkdisplay-win32.c: Don't call ReleaseDC() unnecessarily
The dummy Win32 window that we use to capture display change events and
to create dummy WGL contexts was created with CS_OWNDC, so we really do
not need to (and should not) call ReleaseDC() on the HDC that we
obtained from it, so drop these calls.
2021-07-22 16:28:16 +02:00
Chun-wei Fan
bd69d7e23f GDK-Win32: init_gl(): Default to WGL for now
Since the shaders need to be updated for using with GLES (libANGLE at
least), default to WGL for now.  Unfortunately it is not that common for
Windows to have GLES support, in which the easiest way to obtain such
support is via Google's libANGLE.
2021-07-22 16:28:16 +02:00
Chun-wei Fan
8648486400 GDK-Win32: Fixup, and cleanup WGL HDC handling
It turns out that the problem of the WGL window not drawing was due to
the fact that I messed up where I placed SwapBuffers() during the
conversion... doh:|

At the same time, stop storing the HDC in the GdkWin32GLContextWGL, but
instead always create it along the surface we created, so that it is ready
for use for operating with WGL when we are not dealing with "surfaceless"
contexts.  If we are dealing with "surfaceless" contexts, just use the
HDC of the dummy window that we created when we created the
Gdk(Win32)Display.

WGL contexts should now be in working order at this point.
2021-07-22 16:28:16 +02:00
Chun-wei Fan
6c00117119 Split out WGL/EGL stuff and simplify things
This commit attempts to split GdkWin32GLContext into two parts, one for
WGL and the other for EGL (ANGLE), and attempts to simplify things a
bit, by:

*  We are already creating a Win32 window to capture display changes,
   so we can just use that to act as our dummy window that we use to
   find out the pixel format that the system supports for WGL.  We also
   use it to obtain the dummy legacy WGL context that we will always
   require to create our more advanced Core WGL contexts.

*  Like what is done in X11, store up the WGL pixel format or the
   EGLConfig in our GdkWin32Display.

*  Ensure we do not create the dummy WGL context unnecessarily.

In this way, we can successfully create the WGL/EGL contexts, however
there are some issues at this point:

*  For WGL, the code successfully initializes and realizes the WGL
   Contexts, but for some reason things became invisible.  When running
   gtk4-demo, this can be verified by seeing the mouse cursor changing
   when moved to spots where one can resize the window, although they
   were invisible.

*  For EGL, the code initializes EGL but could not realize the EGL
   context as shaders failed to compile.  It seems like the shader issue
   is definitely outside the scope of this MR.
2021-07-22 16:28:16 +02:00
Benjamin Otte
9c4c4eaaa1 gl: Fix issue with EGL + nvidia
nvidia sets the default draw buffer to GL_NONE if EGL contexts are
initially bound to EGL_NO_SURFACE which is exactly what we are doing. So
bind them to GL_BACK when drawing, as they should be.

See https://phabricator.services.mozilla.com/D118743 for a discussion
about EGL_NO_CONTEXT and draw buffers.
2021-07-22 16:28:16 +02:00
Chun-wei Fan
969b3257a7 GDK: Add debug option for WGL usage
This way, one can force using WGL on Windows even if EGL support was
enabled.  Also update the help text for gl-egl as it will apply for
Windows, albeit a bit later.
2021-07-22 16:28:16 +02:00
Chun-wei Fan
65c6af31e1 GDK-Win32: Move some functions out of gdkglcontext-win32.c
We want these to be out of the way as we split between WGL and EGL/ANGLE
GL contexts, so that they don't get in the way.
2021-07-22 16:28:16 +02:00
Benjamin Otte
6b8bc83420 display: Move GL selection code into gdkdisplay-x11.c
This has the benefit that we can refactor it and make sure we deal with
GdkDisplay::init_gl() not being called at all because
GDK_DEBUG=gl-disable had been specified.
2021-07-22 16:28:16 +02:00
Benjamin Otte
30aaab5c6c x11: Move code from GdkGLContextX11
It's not used there, but both backends have independent
immplementationgs for it.

I want to get rid of GdkGLContextX11 and moving code from it is the
first step.
2021-07-22 16:28:16 +02:00
Benjamin Otte
72e2a46c05 inspector: Add support for displaying GL errors
Also, no need to show a GL version if GL isn't available.
2021-07-22 16:27:32 +02:00
Benjamin Otte
e06e0e8555 gdk: Move GL context construction to GdkGLContext
Now that we have the display's context to hook into, we can use it to
construct other GL contexts and don't need a GdkSurface vfunc anymore.

This has the added benefit that backends can have different GdkGLContext
classes on the display and get new GLContexts generated from them, so
we get multiple GL backend support per GDK backend for free.

I originally wanted to make this a vfunc on GdkGLContextClass, but
it turns out all the abckends would just call g_object_new() anyway.
2021-07-22 16:27:32 +02:00
Benjamin Otte
9f1d6e1f44 gl: Move vfunc
Instead of
  Display::make_gl_context_current()
we now have
  GLContext::clear_current()
  GLContext::make_current()

This fits better with the backends (we can actually implement
clearCurrent on macOS now) and makes it easier to implement different GL
backends for backends (like EGL/GLX on X11).

We also pass a surfaceless boolean to make_current() so the calling code
can decide if a surface needs to be bound or not, because the backends
were all doing whatever, which was very counterproductive.
2021-07-22 16:27:32 +02:00
Benjamin Otte
15ed1a329e gl: Require EGL_KHR_surfaceless_context with egl
The code to create and manage a fake egl surface to bind to is
complex and completely untested because everyone seems to support this
extension.

nvidia and Mesa do support it and according to Mesa devs, adding support
in a new driver is rather simple and Mesa drivers gain that feature
automatically, so all future drivers shoould have it.
2021-07-22 16:27:31 +02:00
Benjamin Otte
505436340b gdk: Get rid of paint contexts
... or more exactly: Only use paint contexts with
gdk_cairo_draw_from_gl().

Instead of paint contexts being the only contexts who call swapBuffer(),
any context can be used for this, when it's used with
begin_frame()/end_frame().

This removes 2 features:

1. We no longer need a big sharing hierarchy. All contexts are now
   shared with gdk_display_get_gl_context().
2. There is no longer a difference between attached and non-attached
   contexts. All contexts work the same way.
2021-07-22 16:27:31 +02:00
Benjamin Otte
a27434a8a7 gl: Store the context::in-frame state in the current context
Do not treat the context as already current when the value
of context::in-frame changes.

This is so we can bind to EGL_NO_SURFACE if context::in-frame == false
and to context::surface if context::in-frame == true.

This allows getting rid of the attached property in future commits.
2021-07-22 16:27:31 +02:00
Benjamin Otte
2c987861a6 gl: Deprecate gdk_gl_context_get_shared_context()
It's not used anymore. And in particular we do want to keep the display
context private, so we're not gonna return it from this function.
2021-07-22 16:27:31 +02:00
Benjamin Otte
c7320df0c9 gdk: Add gdk_gl_context_is_shared()
... and use it in the GL renderers.
2021-07-22 16:27:31 +02:00
Benjamin Otte
dd666e4fe4 ngl: Store the shared driver in the display
... instead of some random GL context.
2021-07-22 16:23:56 +02:00
Benjamin Otte
e4f0418003 gdk: Require EGL version 1.4 across the board
Mesa currently ships 1.5.
2021-07-22 16:23:56 +02:00
Benjamin Otte
430b6f8fb1 gdk: Add GdkDisplay::init_gl vfunc
The vfunc is called to initialize GL and it returns a "base" context
that GDK then uses as the context all others are shared with. So the GL
context share tree now looks like:

+ context from init_gl
  - context1
  - context2
  ...

So this is a flat tree now, the complexity is gone.

The only caveat is that backends now need to create a GL context when
initializing GL so some refactoring was needed.

Two new functions have been added:

* gdk_display_prepare_gl()
  This is public API and can be used to ensure that GL has been
  initialized or if not, retrieve an error to display (or debug-print).
* gdk_display_get_gl_context()
  This is a private function to retrieve the base context from
  init_gl(). It replaces gdk_surface_get_shared_data_context().
2021-07-22 16:23:56 +02:00
Benjamin Otte
ba3e80cbfa wayland: Don't pass GL config to get_egl_surface()
There's only one GL config.
2021-07-22 16:23:56 +02:00
Benjamin Otte
7cd4282bad wayland: Move fbconfig into the display
Create it during init and then reuse it for all contexts.

While doing that, also improve error reporting - that's not used yet but
will in later commits.
2021-07-22 16:23:56 +02:00
Benjamin Otte
01e9fa9adb gdk: Allow GdkDrawContext with a %NULL surface
This is not used yet, but it allows surfaceless GL contexts.

For that purpose, we need to make the display a construct-only property,
so that it can be set when the surface isn't.

This adds a bunch of very picky checks in the constructor so nothing bad
can happen.
2021-07-22 16:23:56 +02:00
Benjamin Otte
581e01b2da gdk: Add a private struct to GdkDisplay
... and move some members from the GdkDisplay struct.

We've always wanted to add one to isolate the display from the backends
a bit more, but so far it's never happened.

Now that I'm about to add more data to GdkDisplay, it's a good excuse to
start.
2021-07-22 16:23:56 +02:00
Benjamin Otte
5a3b4de1b7 x11: Redo choice between EGL and GLX
We try EGL first, but are very picky about what we accept.
If that fails, we try to go with GLX instead.
And if that also fails, we try EGL again, but this time accept anything.

The idea here is that EGL is the preferred method going forward, but GLX is
the tried and tested method that we know works. So if we detect issues with
EGL, we want to avoid using it in favor of GLX.

Also add a GDK_DEBUG=gl-egl option to force EGL at all costs and not try
GLX.
2021-07-22 16:23:56 +02:00
Benjamin Otte
74288eceaf x11: Properly record the error when initializing GL
That way, we can give a useful error message when things break down for
users.

These error messages could still be improved in places (like looking at
the actual EGL error codes), but that seemed overkill.
2021-07-22 16:23:56 +02:00
Benjamin Otte
37ba057128 x11: Do not call glXQueryExtension()
epoxy does that already.
2021-07-22 16:23:56 +02:00
Benjamin Otte
6d5ba9590b x11: Get Visual from EGL directly
Query the EGL_VISUAL_ID from the egl Config and select a config with the
matching Visual.

This is currently broken on Mesa because it does not expose any RGBA
X Visuals in any EGL config, so we always end up with opaque Windows.

https://gitlab.freedesktop.org/mesa/mesa/-/issues/149
2021-07-22 16:23:56 +02:00
Benjamin Otte
215f792851 x11: Store the GLX drawable in the surface
Also, stop using a dummy window for unattached GL contexts and instead
use the display's leader surface.

Again, this mirrors EGL.
2021-07-22 16:23:56 +02:00
Benjamin Otte
1c55b32879 x11: Use single GLX fbconfig and store it in the display
This mirrors the code for the EGL config.
2021-07-22 16:23:56 +02:00
Benjamin Otte
82eb947f41 x11: Remove glx version check
We only work with GLX >= 1.3 anyway, so don't explicitly check for it
and pretend to do something else that doesn't work otherwise.
2021-07-22 16:06:06 +02:00
Benjamin Otte
485dae9f25 x11: Remove unused struct member
We don't care if the GL context is direct at all.
2021-07-22 16:06:06 +02:00
Benjamin Otte
eb3423312f Revert "x11: Always fall back to GLX on NVIDIA"
This reverts commit c35a6725b9.

This approach doesn't work because if NVIDIA doesn't work for EGL, the
EGL implementation won't be provided by NVIDIA, so checking the vendor
doesn't work.
2021-07-22 16:06:06 +02:00
Benjamin Otte
04c2093d5c x11: Remove the dummy surface
Instead, use the display's "leader surface" when no surface is required,
because we have it lying around.

Really, we want to use EGL_NO_SURFACE, but if that's not supported...
2021-07-22 16:06:06 +02:00
Benjamin Otte
ccd5992a83 x11: Remove GdkVisual
It's not used anymore.
2021-07-22 16:06:06 +02:00
Benjamin Otte
ca8d9fbe0b x11: Rework Visual selection
Instead of going via GdkVisual, doing a preselection and letting the GL
initialization improve it, let the GL initialization pick an X Visual
directly using X Visual code directly.

The code should select the same visuals as before as it tries to apply
the same logic, but it's a rewrite, so I expect I messed something up.
2021-07-22 16:06:06 +02:00
Benjamin Otte
62bac44a21 glx: Remove Visual cache
1. We're using EGL most of the time anyway, so if we wanted to cache
   things, we'd need to port it there.
2. Our GL handling is massively configurable, so determining when to use
   the cache and when not is a challenge.
3. It makes startup nondeterministic and depend on whether a GTK4 app
   has previously been started on this display and nobody thinks about
   that when debugging.
4. The only benefit of the caching is delaying GL initialization - which
   made sense in GTK3 where almost no app used GL but doesn't make sense
   in GTK4 where almost every app uses GL.

So unless I find a big benefit to reintroducing it, this cache will be
gone for good.
2021-07-22 16:06:05 +02:00
Benjamin Otte
0ddd06113d x11: Move GL init code into the GL context
No functional changes, just shuffling code.
2021-07-22 16:06:05 +02:00
Benjamin Otte
b1fbc2ef24 x11: Store the EGL surface in the GdkSurfaceX11
Avoids having to use private data, though the benefit is somewhat
limited as we still have to put the destructor in the egl code and can't
just put it in gdk_surface_x11_finalize().
2021-07-22 16:06:05 +02:00
Benjamin Otte
c787fe7ecb x11: Store the EGL config in the display
We only have one config, because we use the same Visual everywhere.
Store this config in the GdkDisplayX11 struct for easy access.

Also do this on initialize, because if creating the config fails, we
want to switch to GLX instead of failing to do GL at all.

This also simplifies a lot of code as we can share Visual, Colormap, etc
across surfaces.
2021-07-22 16:06:05 +02:00
Benjamin Otte
bdb49720be x11: Move the EGL display into the private struct
There's no need to use g_object_set_data() for it.

We can also stop caching it elsewhere because we know the display has
it.

And finally, we can remove the display->have_egl boolean and use
display->egl_display != NULL instead. We initialize the display at
startup, so that variable is the perfect indicator.
2021-07-22 16:06:05 +02:00
Benjamin Otte
1d448a2b8a x11: Pass the display, not the screen
Screens are on their way out.
2021-07-22 16:06:05 +02:00
Benjamin Otte
c5df081904 x11: Simplify code
These variables were a lot more important in GTK3, but now we just want
to pass them through to X.
2021-07-22 16:06:05 +02:00
Benjamin Otte
8a2f3e1fe5 x11: Move function call
The GLX visual selection is GLX specific, so it can be handled by the GLX
code.

There should be no reordering here, the call was just moved.
2021-07-22 16:06:05 +02:00
Benjamin Otte
8dfc627e46 glx: Don't initialize GLX multiple times.
Either it is initialized or it isn't.
2021-07-22 16:06:05 +02:00
Benjamin Otte
0fce30070f x11: Initialize GL at startup
We need to initialize GL to select the Visual we are going to use for
all our Windows.

As the Visual needs to be known before we know if we are even gonna use
GL later, we can't avoid initializing it.

Note that this previously happened, too. It was just hidden behind the
GdkScreen initialization.
2021-07-22 16:06:05 +02:00
Benjamin Otte
8bfe82f686 x11: Don't share cached GLX visuals with GTK3
We don't want to bind ourselves to GTK3 - both because we don't want to
accidentally cause bugs in a different codebase and because we want to
deviate from it.

While doing so, also store visuals as visuals and not as integers.
And only store one Visual because GTK4 only uses one visual.

And then remove the code that is leftover for dealing with the
compatibility Visual for GTK3.

PS: I'm kinda proud of my STRINGIFY_WITHOUT_BRACKETS hack.
2021-07-22 16:06:05 +02:00
Benjamin Otte
7d32ec51e7 x11: Reorder code
Initialize the GL visuals from gdkdisplay.c so the call into the GL
stack isn't hidden in gdkvisual.c

This is relevant for further commits.
2021-07-22 16:06:05 +02:00
Benjamin Otte
5784f8c2f9 x11: Stop reordering visuals
The old code was ordering visuals by depth, but considering that these
days we either use the default visual or a 32bit RGBA visual, that
reordering does not have an effect anymore.

In theory, the only effect is that the GLX Visual selection might select
a different replacement Visual when it checks for improved GL Visuals, but
even there I can't come up with a case where that matters, because
again, the visuals are only reordered by depth and we want to keep the
depth.

In any case, make this a separate commit so bisecting can find this
problem if it ever shows up.
2021-07-22 16:06:05 +02:00
Benjamin Otte
74e01ddec5 x11: Remove unused function
Now that we can't create extra GdkX11Screens anymore, this also means
that there is exactly 1 GdkX11Screen per GdkX11Display.
2021-07-22 16:06:05 +02:00
Benjamin Otte
1347573139 x11: Move code where it belongs
Instead of the display telling the screen to tell the visuals to tell
the display to initialize itself, just init the display directly.

What a concept.
2021-07-22 16:06:05 +02:00
Benjamin Otte
f2b41e708d build: Build demos before tools
That's a sneaky trick so my edit/compile/test cycle goes faster:
I usually use demos for testing so the tools don't have to be linked for
me to start testing.
2021-07-22 16:06:05 +02:00
Matthias Clasen
a5555943ed Merge branch 'destroy-pointer-gestures' into 'master'
gdk/wayland: Clean up gestures if pointer capability is withdrawn

See merge request GNOME/gtk!3697
2021-07-21 21:33:53 +00:00
Vlad Zahorodnii
2c023cdaed gdk/wayland: Clean up gestures if pointer capability is withdrawn
If the pointer capability is added, pointer swipe and pinch gestures
will be created. However, if the pointer capability is removed, the
gesture objects won't be destroyed.

If the pointer capability is removed and added several times in a row,
for example due to plugging and unplugging physical mouse, this can lead
to leaking the old gesture objects.

In order to prevent that, this change makes the seat destroy swipe and
pinch gestures when the pointer capability is withdrawn.
2021-07-21 20:52:16 +03:00
Matthias Clasen
bcc7028640 Merge branch 'sync-icons' into 'master'
Sync included icons from adwaita-icon-theme

See merge request GNOME/gtk!3773
2021-07-21 17:49:15 +00:00
Matthias Clasen
bdee75cd0f Sync included icons from adwaita-icon-theme
Make sure we stay in sync with the Adwaita.
2021-07-20 17:26:59 -04:00
Matthias Clasen
94eb3d7ac0 Merge branch 'wip/otte/build' into 'master'
Streamline build configuration

See merge request GNOME/gtk!3391
2021-07-20 18:25:59 +00:00
Benjamin Otte
0ae2acfb1a x11: Remove XComposite
It's only used during DND to allow use of the root window's cow window
as a DND target, because apparently gnome-shell used to think that was a
great idea to DND to the overview.

Somebody complain to gnome-shell devs about it not being a good idea if
they want it fixed.
Potentially using Wayland is a better idea though.

This reverts 85ae875dcb

Related: https://bugzilla.gnome.org/show_bug.cgi?id=601731
2021-07-20 14:00:25 -04:00
Benjamin Otte
afc5f46ca9 x11: Remove unused headers 2021-07-20 14:00:25 -04:00
Benjamin Otte
e544c891ca build: Make all X11 extensions mandatory
It's not 2011 anymore, and we shouldn't randomly build one of 10.000
different combinations of X11 backends (I counted the possibilities) but
exactly the one we expect people to use.
2021-07-20 14:00:25 -04:00
Benjamin Otte
af0c95c11a build: Remove sassc option
Instead, ensure that sassc is made madatory on git builds (because
it is, we don't ship CSS files anymore) and not even looked for in
release builds (because do ship CSS files there).
2021-07-20 14:00:25 -04:00
Benjamin Otte
4d5dc18a57 build: disable Vulkan by default
We don't want people to build Vulkan support when they just want to get
GTK built.

This is in particular true for GTK as a CI subproject or for people
using jhbuild.

Worse, just having Vulkan support compiled in tends to cause crashes
in the Inspector, even if you are not using it.
2021-07-20 14:00:25 -04:00
Benjamin Otte
9f6fb161e2 build: Set proper defaults for media backends
GTK supports webm playback, which means a backend should always be
compiled.

The ffmpeg backend however is incomplete (no audio) and as such, we
don't want people to end up with it accidentally.

Since we don't want to drag an entire gstreamer build into our ci
on MacOs or msvc, explicitly disable the gstreame media backend there.
2021-07-20 14:00:25 -04:00
Matthias Clasen
3883a98771 Merge branch 'fix-dialog-docs' into 'master'
gtk/builder: Port example to GTK 4

See merge request GNOME/gtk!3772
2021-07-20 12:54:55 +00:00
Yuri Chornoivan
9b44965f13 Update Ukrainian translation 2021-07-20 12:08:13 +00:00
Maximiliano Sandoval R
aa6a9de6ba gtk/builder: Port example to GTK 4 2021-07-20 13:22:08 +02:00
Matthias Clasen
8669e8a498 Merge branch 'tooltip-hig' into 'master'
password_entry: Header Capitalization on tooltip

See merge request GNOME/gtk!3771
2021-07-20 11:17:36 +00:00
Maximiliano Sandoval R
ead31db096 password_entry: Header Capitalization on tooltip
See https://teams.pages.gitlab.gnome.org/Design/hig-www/feedback/tooltips.html
2021-07-20 13:00:05 +02:00
Matthias Clasen
69fda941c7 Merge branch 'win32.hidpi.cleanup' into 'master'
GDK-Win32: Clean up HiDPI support and WGL slightly

Closes #3796

See merge request GNOME/gtk!3767
2021-07-20 02:43:43 +00:00
Matthias Clasen
67c9e7a4a8 Merge branch 'ci-default-settings-4' into 'master'
reftests: Enforce default settings

See merge request GNOME/gtk!3769
2021-07-19 18:36:11 +00:00
Matthias Clasen
4e4f57e091 reftests: Enforce default settings
Set all settings to their default values, so we
are less dependent on the environment to be set
up just right. In particular, this fixes animations
being disabled when we happen to run in a vm.
2021-07-19 13:26:32 -04:00
Chun-wei Fan
ac64d2d910 GDK-Win32: Clean up HiDPI support and WGL a bit
Make _gdk_win32_display_get_monitor_scale_factor() less complex, by:

*  Drop the preceding underscore.

*  Dropping an unused parameter.

*  Using a GdkSurface instead of a HWND, as the HWND that we pass into
   this function might have been taken from a GdkSurface, which are now
   always created with CS_OWNDC.  This means if a GdkSurface was passed
   in, we ensure that we only acquire the DC from the HWND once, and do
   not attempt to call ReleaseDC() on it.

*  Store the HDC that we acquire from the GdkSurface's HWND into the
   surface, and use that as the HDC we need for our GdkGLContext.

*  Drop the gl_hwnd from GdkWin32Display, as that is really should be
   stored in the GdkSurface.

*  For functions that were updated, name GdkWin32Display variables as
   display_win32 and GdkSurface variables as surface, to unify things.

*  Stop calling ReleaseDC() on the HDC that we use for OpenGL, since
   they were acquired from HWND's created with CS_OWNDC.
2021-07-19 18:30:42 +08:00
Chun-wei Fan
49a76257cd gdksurface-win32.c: Create all surfaces with CS_OWNDC
We want to ensure that we have things set up properly for drag surfaces
as well.
2021-07-19 17:36:54 +08:00
Matthias Clasen
77829cf3ed Merge branch 'pango-main' into 'master'
Use pango from the main branch

See merge request GNOME/gtk!3762
2021-07-17 13:05:42 +00:00
Yuri Chornoivan
4d10ab3d35 Update Ukrainian translation 2021-07-17 05:34:21 +00:00
Matthias Clasen
e609ede597 Use pango from the main branch
Change the Pango subproject to use the main branch.

This depends on
https://gitlab.gnome.org/GNOME/pango/-/merge_requests/379
2021-07-16 13:19:22 -04:00
Benjamin Otte
2ba69abe39 Merge branch 'wip/otte/for-master' into 'master'
cssimagecrossfade: Don't abort() when failing to parse image

Closes #4101

See merge request GNOME/gtk!3758
2021-07-16 16:26:23 +00:00
Benjamin Otte
a76f515569 cssimagecrossfade: Don't abort() when failing to parse image
The code wasn't checking if parsing an image failed and just returning
success.

Testcase from bug is attached.

Fixes #4101
2021-07-16 17:50:09 +02:00
Matthias Clasen
a663b8c313 Merge branch 'fix-negative-scales' into 'master'
ngl: Handle negative scales

Closes #4096

See merge request GNOME/gtk!3755
2021-07-16 11:59:47 +00:00
Matthias Clasen
f66fa16bd1 Merge branch 'metainfo' into 'master'
metadata: Fix license identifiers and appdata

See merge request GNOME/gtk!3757
2021-07-16 11:14:09 +00:00
Matthias Clasen
8390363abe testsuite: Avoid negative scales with gl renderer
The fix in 1c90bb522e was only for the ngl renderer,
so don't use the test with the gl renderer, until it is
fixed as well.
2021-07-16 07:11:20 -04:00
Matthias Clasen
6ff85d287a Merge branch 'wip/chergert/fix-texthistory-insert' into 'master'
texthistory: fix calculation of n_chars

See merge request GNOME/gtk!3756
2021-07-16 11:04:21 +00:00
Maximiliano Sandoval R
94c2072be8 meson: Use a valid SPDX identifier
See https://mesonbuild.com/Reference-manual.html#license
2021-07-16 11:14:46 +02:00
Maximiliano Sandoval R
64b9d53472 appdata: Use launchable rather than id
<id> should be used for the component id and <launchable> for the
desktop file.
2021-07-16 11:14:46 +02:00
Maximiliano Sandoval R
a5e7b92c5d appdata: Add content_rating
https://www.freedesktop.org/software/appstream/docs/chap-Metadata.html#tag-content_rating
2021-07-16 11:14:42 +02:00
Maximiliano Sandoval R
2da9ba63e2 appdata: Use correct SPDX license identifier
Following
https://www.freedesktop.org/software/appstream/docs/chap-Metadata.html#tag-project_license,
for the complete list of identifiers see https://spdx.org/licenses/
2021-07-16 11:09:28 +02:00
Christian Hergert
5d02a8f5db texthistory: fix calculation of n_chars
This should be the number of characters, not the end position. This fixes
an issue where we wouldn't coalesce insert actions together.
2021-07-15 21:26:30 -07:00
Benjamin Otte
834d3749c6 testsuite: Add test for crasher
Test for the crasher in !4096
2021-07-15 23:43:28 +02:00
Matthias Clasen
1c90bb522e ngl: Handle negative scales
Scale factors can be negative, but we were not
looking out for that, triggering an assertion when
trying to create a render target with negative
width of height. Avoid that.

Fixes: #4096
2021-07-15 16:40:13 -04:00
Matthias Clasen
b70b058b66 Merge branch 'transparent-optimizations' into 'master'
snapshot: Handle transparent opacity nodes correctly

See merge request GNOME/gtk!3754
2021-07-15 18:39:48 +00:00
Matthias Clasen
b99beeb552 Merge branch 'wip/baedert/for-master' into 'master'
snapshot: Replace trivial gradients with color nodes

See merge request GNOME/gtk!3753
2021-07-15 18:31:22 +00:00
Matthias Clasen
c799452973 ngl: Do nothing for transparent text nodes
Like the previous commit - a transparent text node
will not produce any visible pixels, so bail out early.
2021-07-15 13:18:23 -04:00
Matthias Clasen
fd48afb77d ngl: Do nothing for transparent color nodes
No need to send commands to the GPU to render transparency.
2021-07-15 13:18:23 -04:00
Matthias Clasen
aaa68954c3 snapshot: Handle transparent opacity nodes correctly
Eliding totally transparent content from the node tree is
not 100% correct, since filters can make things visible, so
we need to at least preserve the bounds. We can do that by
creating a transparent color node.
2021-07-15 13:18:23 -04:00
Timm Bäder
433233258b snapshot: Only compute start and end point if we have to
If the linear gradient results in a color node, we don't need the start
and end point. Only declare and compute it if we need to.
2021-07-15 16:52:38 +02:00
Timm Bäder
3eed61deba snapshot: Replace trivial gradients with color nodes
Extend this to all existing gradient types
2021-07-15 16:51:17 +02:00
Matthias Clasen
87e2a02e0c composetable: Rewrite Compose files if necessary
Apply heuristics to avoid breaking users existing configurations
with the change to not always add the default sequences.

If we find a cache that was generated before 4.4, and the Compose
file does not have an include, and doesn't contain so many sequences
that it is probably a copy of the system one, we take steps to keep
things working, and thell the user about it.
2021-07-15 09:30:09 -04:00
Matthias Clasen
264d592012 composetable: Keep the number of sequences
And print it out in tests.

Update all tests for this.
2021-07-15 09:30:01 -04:00
Matthias Clasen
0ad5094119 Remove some leftover debug code 2021-07-15 09:30:01 -04:00
Benjamin Otte
67952a9142 Merge branch 'wip/otte/for-master' into 'master'
rendernodeparser: Don't use %g when writing file

See merge request GNOME/gtk!3752
2021-07-14 18:46:36 +00:00
Benjamin Otte
ca3d942b9b rendernodeparser: Remove leftover debug prints 2021-07-14 20:19:40 +02:00
Benjamin Otte
5470a1344d rendernodeparser: Don't use %g when writing file
%g is locale dependent and can add "," where "." should be. Use
string_append_double() instead.
2021-07-14 20:18:44 +02:00
Matthias Clasen
4390f8102b imcontext: Improve the docs
Add more details about supported input methods.
2021-07-13 22:03:23 -04:00
Matthias Clasen
92129a2011 imcontext: Simplify checking compose seqs
Add the builtin table to the list of tables, and
remove the duplicated code that checks builtin
sequences separately.
2021-07-13 22:03:23 -04:00
Matthias Clasen
54dffa07f3 composetable: Drop GtkComposeTableCompact
All tables use the compact format now, and we generate
caches in that format too. Bump the cache version to 3
for this.

Replace the python script for generating the builtin table
by a small C program using the same code to generate the data
for the builtin table. This drops the restriction on only
generating a single character in the builtin sequences.
2021-07-13 22:03:23 -04:00
Matthias Clasen
1cff4bb27a composetable: Ignore length 1 sequences
It turns out that the X11 Compose file has some
length 1 sequences which are not interesting to us.
2021-07-13 22:02:33 -04:00
Matthias Clasen
8087250476 imcontext: Replace the builtin sequences
When we find a Compose file, replace the builtin
sequences with the table we found. This matches the
semantics described in Compose(5), and makes it possible
to drop unwanted sequences from the builtin table.

It is slight change of behavior for users with existing
Compose files. To match the previous behavior, you have
to add

include "%L"

to your Compose file, to keep the builtin sequences in
addition to your own.
2021-07-13 22:02:33 -04:00
Matthias Clasen
485dc052ca composetable: Allow removing sequences
Interpret an empty string as value in the Compose
file to mean: Remove this sequence.

Tests included.
2021-07-13 22:02:33 -04:00
Matthias Clasen
45d39c2802 composetable: Switch to using a hash table
This lets us naturally replace matching sequences
while parsing. That means that the semantics are now
"last one wins" if the parser sees multiple entries
for the same sequence.

Add a testcase that checks the new replacement semantics.
2021-07-13 22:02:33 -04:00
Matthias Clasen
3b4b1c6878 composetable: Reinterpret %L
When we see include "%L" in a Compose file, use the
builtin sequences. We no longer filter out duplicates
wrt. to the builtin sequences.
2021-07-13 22:02:33 -04:00
Matthias Clasen
ff4f07d76f composetable: Handle substitutions in includes
Hande the %H, %L, %S substitutions that are described
in Compose(7).

Test included.
2021-07-13 22:02:33 -04:00
Matthias Clasen
fb6c8cd466 composetable: Handle includes
This adds the mechanics for parsing include lines in
Compose files. We do detect and prevent cycles.

Tests included.
2021-07-13 22:02:33 -04:00
Matthias Clasen
8464b0484f composetable: Move code into the parser
This is just code reshuffling.
2021-07-13 22:02:33 -04:00
Matthias Clasen
bee58fd09d composetable: Introduce a parser struct
This will be used in the following commits to
beef up Compose file parsing.
2021-07-13 22:02:33 -04:00
Matthias Clasen
d25557a5ef Clean up the GtkComposeTable api
Keep the list of composetables private to GtkIMContextSimple,
and just have an api that creates new GtkComposeTables, either
from a file or from data.

Update tests to use the new api.
2021-07-13 22:02:33 -04:00
Matthias Clasen
da3ca6604b gtk-demo: Add a slider to the menu example
This is a fun way to show that we can scale fast.
2021-07-13 22:02:33 -04:00
Matthias Clasen
74cba6c3b2 Add a simple Javascript example
This shows how to use a layout manager in a widget,
implemented in javascript. The example sets up the
environment for running from the toplevel dir, assuming
that the build dir is called 'build'.
2021-07-13 22:02:33 -04:00
Emmanuele Bassi
c09718b731 Merge branch 'doc-fixes' into 'master'
doc: Syntax fixes

See merge request GNOME/gtk!3751
2021-07-13 23:43:06 +00:00
Marco Melorio
eacfa2a966 doc: Syntax fixes 2021-07-13 22:53:19 +00:00
Matthias Clasen
e7f228e240 Merge branch 'fp16-tests' into 'master'
ngl: Make the C half-float implementation accessible

See merge request GNOME/gtk!3748
2021-07-13 13:38:21 +00:00
Matthias Clasen
fab82a7c25 tests: Add some fp16 tests 2021-07-13 09:03:49 -04:00
Matthias Clasen
fc9c34897a ngl: Make the C half-float implementation accessible
Make this accessible for tests.
2021-07-13 09:03:49 -04:00
Emmanuele Bassi
28cdd3f497 Merge branch 'gi-fixes' into 'master'
Various introspection fixes

See merge request GNOME/gtk!3747
2021-07-13 11:21:20 +00:00
Marc-André Lureau
a009e26e95 gtk: fix GtkPasswordEntryBuffer introspection
Move the source file to public_sources list, and fix tag annotation.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-07-13 15:03:09 +04:00
Marc-André Lureau
ab908c23f4 Add GtkMenuButton:primary Since: annotation
Property added in commit a74420bc1a.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-07-13 11:31:09 +04:00
Marc-André Lureau
ae21f66fe5 Add GTK_DEBUG_ICONFALLBACK Since: 4.2 annotation
Introduced in commit 6f82408056.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-07-13 11:26:39 +04:00
Rafael Fontenelle
2d092ea280 Update Brazilian Portuguese translation
(cherry picked from commit c7a7fc4de6)
2021-07-10 19:30:32 +00:00
Rafael Fontenelle
0f9d39cdfd Update Brazilian Portuguese translation
(cherry picked from commit 72c3026764)
2021-07-10 17:14:31 +00:00
Matthias Clasen
a64087d481 Merge branch 'activatable-buttons' into 'master'
menubutton: Make menu buttons activatable again

Closes #4079

See merge request GNOME/gtk!3728
2021-07-10 12:59:39 +00:00
Matthias Clasen
c85f3f4942 Merge branch 'wip/chergert/fix-4094' into 'master'
joinedmenu: add helper to join menus instead of nesting

Closes #4094

See merge request GNOME/gtk!3739
2021-07-09 19:29:41 +00:00
Matthias Clasen
d7553279ff Merge branch 'gdkkeys-m' into 'master'
[master] gdkkeys-win32.c: fix initialisation of key_state in update_keymap

See merge request GNOME/gtk!3742
2021-07-09 10:58:23 +00:00
Matthias Clasen
c86631b8a9 Merge branch 'dynamic-typelib-path' into 'master'
build: Get typelib dir dynamically using gobject-introspection dependency

See merge request GNOME/gtk!3737
2021-07-09 10:57:37 +00:00
Matthias Clasen
c1af63de9b Merge branch 'invisible-char-fix' into 'master'
textbtree: Initialize to zero the tags counting array

See merge request GNOME/gtk!3740
2021-07-09 10:56:51 +00:00
Jeremy Tan
2784b03b2d gdkkeys-win32.c: fix initialisation of key_state in update_keymap
It apparently worked by chance in the past, but now causes e.g.
alphanumeric characters to be interpreted as half-width katakana
when using the Japanese IME.
2021-07-09 12:46:49 +08:00
Marco Trevisan (Treviño)
10bdf8c645 textbtree: Initialize to zero the tags counting array
We're using the tag contents array to count the number of invisible tags
set but we always increase it without being initialized.

This may lead to unexpected behavior when traversing them and it's
causing a reliable failure in the textiter tests under s390x.

So, memset that area content to 0 once allocated. It's not needed to do
the same for the tags themselves as we always assign them.

 Conditional jump or move depends on uninitialised value(s)
   at 0x4CFAA00: _gtk_text_btree_char_is_invisible (gtktextbtree.c:2569)
   by 0x4B8A1BB: find_visible_by_log_attrs (gtktextiter.c:3244)
   by 0x10E93D: check_backward_visible_word_start (textiter.c:484)
   by 0x10E93D: test_visible_word_boundaries (textiter.c:523)
   by 0x533288F: g_test_run_suite (in /usr/lib/s390x-linux-gnu/libglib-2.0.so.0)
   by 0x53328E7: g_test_run (in /usr/lib/s390x-linux-gnu/libglib-2.0.so.0)
   by 0x109CC1: main (textiter.c:807)
2021-07-09 03:48:40 +02:00
Christian Hergert
d63d9b2319 joinedmenu: add helper to join menus instead of nesting
In many cases, we have an "extra-menu" property that is used to allow
applications to join menus into the native menu for the widget. Previously,
this was done by nesting that menu in a section.

Doing so increases the complexity of the rules for GtkMenuTracker as you
may want different handling from inside of the section vs toplevel
sections.

If instead we synthetically glue the menus together, we have a much more
natural joining of menus as the application developer would expect for
their menu.

This also ports GtkLabel, GtkText, GtkPasswordEntry, and GtkTextView to
use the joined menu helper.

The joined menu helper comes originally from GNOME Builder and has had
extensive use there.

Fixes #4094
2021-07-08 14:16:06 -07:00
Marco Trevisan (Treviño)
d5f2b69d0c build: Get typelib dir dynamically using gobject-introspection dependency
We hardcoded the typelib directory for only an arch (and a distro),
while we can just get it from gobject-introspection pkg config if tests
are enabled.
2021-07-08 04:59:10 +02:00
Matthias Clasen
6818eee859 Merge branch 'wip/exalm/scroll-touch' into 'master'
scrolledwindow: Don't check drag threshold when already scrolling

See merge request GNOME/gtk!3735
2021-07-07 21:37:58 +00:00
Matthias Clasen
e7f1398d85 Merge branch 'text-cursor-extents' into 'master'
text: Add API to compute cursor extents

See merge request GNOME/gtk!3734
2021-07-07 21:37:14 +00:00
Matthias Clasen
880c01f8cc Merge branch 'wl-since' into 'master'
Add missing "Since: 4.X" doc tags

See merge request GNOME/gtk!3736
2021-07-07 21:36:13 +00:00
Marc-André Lureau
337c5e5e59 Add missing "Since: 4.X" tags
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-07-07 23:35:38 +04:00
Florian Müllner
af52ea78c6 text: Add API to compute cursor extents
The extents that correspond to the strong/weak cursor at a given
character position can be used for example to point a popover to
text in the widget.
2021-07-07 19:33:12 +02:00
Alexander Mikhaylenko
fe633d9ef9 scrolledwindow: Don't check drag threshold when already scrolling
Checkout the drag threshold only makes sense when starting a scroll, after
that it just adds jumps when trying to scroll back and forth.
2021-07-07 19:39:06 +05:00
Matthias Clasen
e6cce283a7 Merge branch 'matthiasc/for-master' into 'master'
gtk-demo: Add a slider to the menu example

See merge request GNOME/gtk!3733
2021-07-06 00:23:30 +00:00
Matthias Clasen
c920236c54 gtk-demo: Add a slider to the menu example
This is a fun way to show that we can scale fast.
2021-07-05 19:31:54 -04:00
Matthias Clasen
6f86b4d220 Merge branch 'js-example' into 'master'
Add a simple Javascript example

See merge request GNOME/gtk!3731
2021-07-05 20:24:30 +00:00
Matthias Clasen
a085e174c5 Merge branch 'wip/remove-cloudprint' into 'master'
Remove Google Cloud Print backend

See merge request GNOME/gtk!3729
2021-07-05 20:21:52 +00:00
Florentina Mușat
d3c08789a3 Update Romanian translation
(cherry picked from commit 6ff90954dc)
2021-07-05 20:02:15 +00:00
Florentina Mușat
630488210b Update Romanian translation
(cherry picked from commit e5bd6312be)
2021-07-05 19:47:50 +00:00
Matthias Clasen
873f6ccfea Add a simple Javascript example
This shows how to use a layout manager in a widget,
implemented in javascript. The example sets up the
environment for running from the toplevel dir, assuming
that the build dir is called 'build'.
2021-07-05 13:48:51 -04:00
Patrick Griffis
af15f5d004 Remove Google Cloud Print backend
This service was shut down at the start of 2021.

This helpfully removes any dependency on json-glib, librest (and libsoup).
2021-07-05 10:54:16 -05:00
Matthias Clasen
f328175e2f appchooserbutton: Make buttons activatable again
The activation is simply forwarded to the combobox
within.
2021-07-05 10:10:44 -04:00
Matthias Clasen
fc65d6393a colorbutton: Make color buttons activatable again
The activation is simply forwarded to the toggle button
within.
2021-07-05 10:10:19 -04:00
Matthias Clasen
271afb7eab font button: Make font buttons activatable again
The activation is simply forwarded to the toggle button
within.
2021-07-05 10:09:43 -04:00
Matthias Clasen
76133dbea7 menubutton: Make menu buttons activatable again
The activation is simply forwarded to the toggle button
within.

Fixes: #4079
2021-07-05 10:08:43 -04:00
711 changed files with 95436 additions and 95543 deletions

View File

@@ -7,6 +7,7 @@ stages:
- analysis
- docs
- flatpak
- publish
- deploy
.cache-paths: &cache-paths
@@ -24,7 +25,7 @@ variables:
BACKEND_FLAGS: "-Dx11-backend=true -Dwayland-backend=true -Dbroadway-backend=true"
FEATURE_FLAGS: "-Dvulkan=enabled -Dcloudproviders=enabled"
MESON_TEST_TIMEOUT_MULTIPLIER: 3
FEDORA_IMAGE: "registry.gitlab.gnome.org/gnome/gtk/fedora:v32"
FEDORA_IMAGE: "registry.gitlab.gnome.org/gnome/gtk/fedora:v34"
FLATPAK_IMAGE: "registry.gitlab.gnome.org/gnome/gnome-runtime-images/gnome:master"
.only-default:
@@ -57,6 +58,7 @@ style-check-diff:
- "${CI_PROJECT_DIR}/_build/report*.xml"
- "${CI_PROJECT_DIR}/_build/report*.html"
- "${CI_PROJECT_DIR}/_build/testsuite/reftests/output/*/*.png"
- "${CI_PROJECT_DIR}/_build/testsuite/tools/output/*/*"
- "${CI_PROJECT_DIR}/_build/testsuite/gsk/compare/*/*/*.png"
- "${CI_PROJECT_DIR}/_build/testsuite/css/output/*/*.syscap"
- "${CI_PROJECT_DIR}/_build_hello/meson-logs"
@@ -172,6 +174,7 @@ macos:
- meson -Dx11-backend=false
-Dbroadway-backend=true
-Dmacos-backend=true
-Dmedia-gstreamer=disabled
-Dintrospection=disabled
-Dcpp_std=c++11
-Dpixman:tests=disabled
@@ -335,14 +338,11 @@ reference:
paths:
- _reference
pages:
stage: deploy
publish-docs:
stage: publish
needs: ['reference']
script:
- mv _reference/ public/
- cp .gitlab-ci/pages/* public/
artifacts:
paths:
- public
- "curl -X POST -F token=${PAGES_TRIGGER_TOKEN} -F ref=docs-gtk-org https://gitlab.gnome.org/api/v4/projects/665/trigger/pipeline"
only:
- master
refs:
- master

View File

@@ -48,9 +48,12 @@ RUN dnf -y install \
libcloudproviders-devel \
libepoxy-devel \
libffi-devel \
libjpeg-turbo-devel \
libmount-devel \
libpng-devel \
librsvg2 \
libselinux-devel \
libtiff-devel \
libubsan \
libXcomposite-devel \
libXcursor-devel \

View File

@@ -15,7 +15,7 @@ meson \
-Dx11-backend=true \
-Dwayland-backend=true \
-Dbroadway-backend=true \
-Dvulkan=yes \
-Dvulkan=enabled \
-Dprofiler=true \
--werror \
${EXTRA_MESON_FLAGS:-} \

View File

@@ -6,7 +6,7 @@ call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliar
:: FIXME: make warnings fatal
pip3 install --upgrade --user meson==0.56.2 || goto :error
meson _build || goto :error
meson -Dmedia-gstreamer=disabled _build || goto :error
ninja -C _build || goto :error
goto :EOF

View File

@@ -40,7 +40,7 @@ export CCACHE_DIR="${CCACHE_BASEDIR}/_ccache"
# https://gitlab.gnome.org/GNOME/gtk/-/issues/2243
# https://gitlab.gnome.org/GNOME/gtk/-/issues/3002
if ! pkg-config --atleast-version=2.65.0 glib-2.0; then
if ! pkg-config --atleast-version=2.66.0 glib-2.0; then
git clone https://gitlab.gnome.org/GNOME/glib.git _glib
meson setup _glib_build _glib
meson compile -C _glib_build
@@ -48,7 +48,7 @@ if ! pkg-config --atleast-version=2.65.0 glib-2.0; then
fi
pkg-config --modversion glib-2.0
if ! pkg-config --atleast-version=1.47.0 pango; then
if ! pkg-config --atleast-version=1.49.1 pango; then
git clone https://gitlab.gnome.org/GNOME/pango.git _pango
meson setup _pango_build _pango
meson compile -C _pango_build

188
NEWS
View File

@@ -1,3 +1,191 @@
Overview of Changes
===================
* gsk:
- Drop the GL renderer in favor of NGL
* css:
- Add support for line-height
- Add support for text-transform
* GtkTextView:
- Add support for line height
- Add support for text transforms
* Build:
- Require Pango 1.49
Overview of Changes in 4.4.0
============================
* Input:
- Match IBus for display of Compose sequences
- Match IBus for handling of mismatches
- Handle Escape in Compose sequences
- Allow multiple dead keys
- Support 32bit keysyms
* GtkCheckButton:
- Activate when moving focus
* GtkLabel:
- Propertly ignore double underscores for mnemonics
* GtkPopoverMenu:
- Fix focus cycling
* GtkTextView:
- Improve word selection
- Fix block cursors on empty lines
* GdkToplevel:
- Support the gnome-shell titlebar gesture protocol
* GdkDropTarget:
- Allow creating drop targets in ui files
* gsk:
- Handle partial color fonts correctly
- Use harfbuzz for color font information
- Avoid pango for glyph cache rendering
- Shrink shadow extents
* Settings:
- Change the default for gtk-split-cursor to FALSE
* Demos:
- Small improvements to widget-factory
- gtk-demo: Improve the hypertext demo
- gtk-dem: Improve the clipboard demo
* X11:
- Set WM_CLASS on toplevels
* Wayland:
- Support wl_seat v7
* Windows:
- Drop the local DND protocol
- Avoid WGL if shaders don't work
- Use WinPointer API
* Translation updates:
Belarusian
Friulian
Hebrew
Khmer
Persian
Polish
Overview of Changes in 4.3.2
============================
* GtkToggleButton:
- Fix the actionable implementation
* GtkCheckButton:
- Fix the actionable implementation
- Cancel activation on when the pointer leaves
* GtkMenuButton:
- Make activatable again
- Add a way to have an icon + arrow
* GtkColorButton:
- Make activatable again
* GtkFontButton:
- Make activatable again
* GtkAppChooserButton:
- Make activatable again
* GtkColumnView:
- Fix double activation
* GtkLabel:
- Fix mnemonics without markup
* GtkTreeView:
- Clip header buttons
* GtkTextView:
- Add api to get the RTL and LTR contexts
- Fix some errors in text history grouping
* GtkText:
- Don't show placeholder text on top of entry text
- Add api to compute the cursor extents
- Fix y coordinates for text selection
* GtkFileChooser:
- Don't show Trash in the side bar
* GtkPopoverMenu:
- Add scrollbars to long menus
* GtkActionMuxer:
- Fix propagation of accel changes
* Introspection:
- Annotate all filename arguments
- Rename GtkMediaStream apis to avoid name collisions
- Rename GtkDropTarget properties to avoid name collisions
- Make GtkPasswordEntryBuffer introspectable
* Printing:
- Remove the Google Cloud Print backend
* Theme:
- Sync included icons with the Adwaita icon theme
* GSK:
- Avoid overflowing the vertex counter
- Handle negative scales correctly in the ngl renderer
* GDK:
- Cleanup and simplify OpenGL setup code
- Add a GdkDisplay::init_gl vfunc and gdk_display_prepare_gl() api
- Require EGL 1.4
- Fix EGL + NVidia
* Build:
- Enable gstreamer by default
- Disable Vulkan by default
- Remove the sassc option
- Remove options and checks for X11 extensions
* X11:
- Stop using XComposite
- Remove the Visual cache
* Wayland:
- Fix some DND corner cases
- Work with version 2 of pointer-gestures-v1
- Look for cursor themes in $HOME/.icons
* Windows:
- Fix SIGILL on x64 due to popcnt
- Fix popup placement
- Fix drag icon placement
- Clean up HiDPI and WGL support
- Default to WGL
* MacOs:
- Fix input method support
- Register known clipboard types for drop targets
- Add initial DND support
* Translation updates:
Brazilian Portuguese
Portuguese
Romanian
Turkish
Ukrainian
Overview of Changes in 4.3.1
============================

View File

@@ -10,10 +10,12 @@ GTK is a multi-platform toolkit for creating graphical user interfaces.
Offering a complete set of widgets, GTK is suitable for projects ranging
from small one-off projects to complete application suites.
GTK is free software and part of the GNU Project. However, the
licensing terms for GTK, the GNU LGPL, allow it to be used by all
developers, including those developing proprietary software, without any
license fees or royalties.
GTK is a free and open-source software project. The licensing terms
for GTK, the GNU LGPL, allow it to be used by all developers, including those
developing proprietary software, without any license fees or royalties.
GTK is hosted by the GNOME project (thanks!) and used by a wide variety
of applications and projects.
The official download location
@@ -151,6 +153,9 @@ Contributing to GTK
Please, follow the [contribution guide](./CONTRIBUTING.md) to know how to
start contributing to GTK.
If you want to support GTK financially, please consider donating to
the GNOME project, which runs the infrastructure hosting GTK.
Release notes
-------------

View File

@@ -1,289 +0,0 @@
/* always defined to indicate that i18n is enabled */
#define ENABLE_NLS 1
/* Use structured logging */
#define G_LOG_STRUCTURED 1
/* The prefix for our gettext translation domains. */
#mesondefine GETTEXT_PACKAGE
/* Disable deprecation warnings from glib */
#mesondefine GLIB_DISABLE_DEPRECATION_WARNINGS
/* Define the location where the catalogs will be installed */
#mesondefine GTK_LOCALEDIR
/* Define to 1 if you have the `bind_textdomain_codeset' function. */
#mesondefine HAVE_BIND_TEXTDOMAIN_CODESET
/* Have the cloudproviders library */
#mesondefine HAVE_CLOUDPROVIDERS
/* define if we have colord */
#mesondefine HAVE_COLORD
/* Define to 1 if you have the <crt_externs.h> header file. */
#mesondefine HAVE_CRT_EXTERNS_H
/* Define to 1 if you have the `dcgettext' function. */
#mesondefine HAVE_DCGETTEXT
/* Define to 1 if you have the <dlfcn.h> header file. */
#mesondefine HAVE_DLFCN_H
/* Have the ffmpeg library */
#mesondefine HAVE_FFMPEG
/* Define to 1 if you have the <ftw.h> header file. */
#mesondefine HAVE_FTW_H
/* Define to 1 if you have the `getpagesize' function. */
#mesondefine HAVE_GETPAGESIZE
/* Define to 1 if you have the `getresuid' function. */
#mesondefine HAVE_GETRESUID
/* Define if gio-unix is available */
#mesondefine HAVE_GIO_UNIX
/* Define if GStreamer support is available */
#mesondefine HAVE_GSTREAMER
/* Define to 1 if you have the <inttypes.h> header file. */
#mesondefine HAVE_INTTYPES_H
/* Define to 1 if the system has the type `IPrintDialogCallback'. */
#mesondefine HAVE_IPRINTDIALOGCALLBACK
/* Define to 1 if you have the <locale.h> header file. */
#mesondefine HAVE_LOCALE_H
/* Define to 1 if you have the `lstat' function. */
#mesondefine HAVE_LSTAT
/* Define to 1 if you have the `mallinfo' function. */
#mesondefine HAVE_MALLINFO
/* Define to 1 if you have the <memory.h> header file. */
#mesondefine HAVE_MEMORY_H
/* Define to 1 if you have the `mkstemp' function. */
#mesondefine HAVE_MKSTEMP
/* Define to 1 if you have the `mlock` function. */
#mesondefine HAVE_MLOCK
/* Define to 1 if you have a working `mmap' system call. */
#mesondefine HAVE_MMAP
/* Define to 1 if you have a working `madvise' system call. */
#mesondefine HAVE_MADVISE
/* Define to 1 if you have the `posix_fallocate' function. */
#mesondefine HAVE_POSIX_FALLOCATE
/* Have the Xrandr extension library */
#mesondefine HAVE_RANDR
/* Have the Xrandr 1.5 extension library */
#mesondefine HAVE_RANDR15
/* Define to 1 if you have the `sincos' function. */
#mesondefine HAVE_SINCOS
/* Define to 1 if you have the <stdint.h> header file. */
#mesondefine HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#mesondefine HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#mesondefine HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#mesondefine HAVE_STRING_H
/* Define to 1 if you have the <sys/mman.h> header file. */
#mesondefine HAVE_SYS_MMAN_H
/* Define to 1 if you have the <sys/param.h> header file. */
#mesondefine HAVE_SYS_PARAM_H
/* Have the sysprof-capture library */
#mesondefine HAVE_SYSPROF
/* Define to 1 if you have the <sys/stat.h> header file. */
#mesondefine HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/time.h> header file. */
#mesondefine HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/types.h> header file. */
#mesondefine HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#mesondefine HAVE_UNISTD_H
/* Have the XCOMPOSITE X extension */
#mesondefine HAVE_XCOMPOSITE
/* Have the Xcursor library */
#mesondefine HAVE_XCURSOR
/* Have the XDAMAGE X extension */
#mesondefine HAVE_XDAMAGE
/* Have the XFIXES X extension */
#mesondefine HAVE_XFIXES
/* Define to 1 if XFree Xinerama is available */
#mesondefine HAVE_XFREE_XINERAMA
/* Have XGenericEvent */
#mesondefine HAVE_XGENERICEVENTS
/* Define to use XKB extension */
#mesondefine HAVE_XKB
/* Have the SYNC extension library */
#mesondefine HAVE_XSYNC
/* Define to 1 if you have the `_lock_file' function */
#mesondefine HAVE__LOCK_FILE
/* Define to 1 if you have the `flockfile' function */
#mesondefine HAVE_FLOCKFILE
/* Define if _NL_MEASUREMENT_MEASUREMENT is available */
#mesondefine HAVE__NL_MEASUREMENT_MEASUREMENT
/* Define if _NL_PAPER_HEIGHT is available */
#mesondefine HAVE__NL_PAPER_HEIGHT
/* Define if _NL_PAPER_WIDTH is available */
#mesondefine HAVE__NL_PAPER_WIDTH
/* Define if _NL_TIME_FIRST_WEEKDAY is available */
#mesondefine HAVE__NL_TIME_FIRST_WEEKDAY
/* Define to the sub-directory where libtool stores uninstalled libraries. */
#mesondefine LT_OBJDIR
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
#mesondefine NO_MINUS_C_MINUS_O
/* Define to the address where bug reports for this package should be sent. */
#mesondefine PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#mesondefine PACKAGE_NAME
/* Define to the full name and version of this package. */
#mesondefine PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#mesondefine PACKAGE_TARNAME
/* Define to the home page for this package. */
#mesondefine PACKAGE_URL
/* Define to the version of this package. */
#mesondefine PACKAGE_VERSION
/* Use NSBundle functions to determine load paths for libraries, translations,
etc. */
#mesondefine QUARTZ_RELOCATION
/* Define to 1 if you have the ANSI C header files. */
#mesondefine STDC_HEADERS
/* Enable extensions on AIX 3, Interix. */
#ifndef _ALL_SOURCE
# undef _ALL_SOURCE
#endif
/* Enable GNU extensions on systems that have them. */
#ifndef _GNU_SOURCE
# undef _GNU_SOURCE
#endif
/* Enable threading extensions on Solaris. */
#ifndef _POSIX_PTHREAD_SEMANTICS
# undef _POSIX_PTHREAD_SEMANTICS
#endif
/* Enable extensions on HP NonStop. */
#ifndef _TANDEM_SOURCE
# undef _TANDEM_SOURCE
#endif
/* Enable general extensions on Solaris. */
#ifndef __EXTENSIONS__
# undef __EXTENSIONS__
#endif
/* Define to 1 if XInput 2.2 is available */
#mesondefine XINPUT_2_2
/* Define to 1 if the X Window System is missing or not being used. */
#mesondefine X_DISPLAY_MISSING
/* Enable large inode numbers on Mac OS X 10.5. */
#ifndef _DARWIN_USE_64_BIT_INODE
# define _DARWIN_USE_64_BIT_INODE 1
#endif
/* Number of bits in a file offset, on hosts where this is settable. */
#mesondefine _FILE_OFFSET_BITS
/* defines how to decorate public symbols while building */
#mesondefine _GDK_EXTERN
/* Define for large files, on AIX-style hosts. */
#mesondefine _LARGE_FILES
/* Define to 1 if on MINIX. */
#mesondefine _MINIX
/* Define to 2 if the system does not provide POSIX.1 features except with
this defined. */
#mesondefine _POSIX_1_SOURCE
/* Define to 1 if you need to in order for `stat' and other things to work. */
#mesondefine _POSIX_SOURCE
/* Define to `int' if <sys/types.h> doesn't define. */
#mesondefine gid_t
/* Define to `int' if <sys/types.h> doesn't define. */
#mesondefine uid_t
/* Define to 1 if linux/memfd.h exists */
#mesondefine HAVE_LINUX_MEMFD_H
#mesondefine HAVE_LINUX_INPUT_H
#mesondefine HAVE_DEV_EVDEV_INPUT_H
#mesondefine GTK_SYSCONFDIR
#mesondefine GTK_LOCALEDIR
#mesondefine GTK_DATADIR
#mesondefine GTK_LIBDIR
#mesondefine GTK_PRINT_BACKENDS
#mesondefine HAVE_CAIRO_SCRIPT_INTERPRETER
#mesondefine HAVE_HARFBUZZ
#mesondefine HAVE_PANGOFT
#mesondefine ISO_CODES_PREFIX
/* Define if tracker3 is available */
#mesondefine HAVE_TRACKER3
#mesondefine HAVE_F16C
/* Does the OS support GDesktopAppInfo? */
#mesondefine HAVE_DESKTOPAPPINFO

View File

@@ -321,6 +321,7 @@
<file>paintable_emblem.c</file>
<file>paintable_mediastream.c</file>
<file>paintable_svg.c</file>
<file>paintable_symbolic.c</file>
<file>panes.c</file>
<file>password_entry.c</file>
<file>peg_solitaire.c</file>

View File

@@ -100,7 +100,11 @@ prepare_drag (GtkDragSource *source,
DemoImage *demo = DEMO_IMAGE (widget);
GdkPaintable *paintable = get_image_paintable (GTK_IMAGE (demo->image));
return gdk_content_provider_new_typed (GDK_TYPE_PAINTABLE, paintable);
/* Textures can be serialized, paintables can't, so special case the textures */
if (GDK_IS_TEXTURE (paintable))
return gdk_content_provider_new_typed (GDK_TYPE_TEXTURE, paintable);
else
return gdk_content_provider_new_typed (GDK_TYPE_PAINTABLE, paintable);
}
static gboolean
@@ -129,7 +133,11 @@ copy_image (GtkWidget *widget,
GdkPaintable *paintable = get_image_paintable (GTK_IMAGE (demo->image));
GValue value = G_VALUE_INIT;
g_value_init (&value, GDK_TYPE_PAINTABLE);
/* Textures can be serialized, paintables can't, so special case the textures */
if (GDK_IS_TEXTURE (paintable))
g_value_init (&value, GDK_TYPE_TEXTURE);
else
g_value_init (&value, GDK_TYPE_PAINTABLE);
g_value_set_object (&value, paintable);
gdk_clipboard_set_value (clipboard, &value);
g_value_unset (&value);
@@ -138,24 +146,46 @@ copy_image (GtkWidget *widget,
g_object_unref (paintable);
}
static void
paste_image_cb (GObject *source,
GAsyncResult *result,
gpointer data)
{
GdkClipboard *clipboard = GDK_CLIPBOARD (source);
DemoImage *demo = DEMO_IMAGE (data);
const GValue *value;
value = gdk_clipboard_read_value_finish (clipboard, result, NULL);
if (value == NULL)
{
gtk_widget_error_bell (GTK_WIDGET (demo));
g_object_unref (demo);
return;
}
gtk_image_set_from_paintable (GTK_IMAGE (demo->image), g_value_get_object (value));
g_object_unref (demo);
}
static void
paste_image (GtkWidget *widget,
const char *action_name,
GVariant *parameter)
{
GdkClipboard *clipboard = gtk_widget_get_clipboard (widget);
DemoImage *demo = DEMO_IMAGE (widget);
GdkContentProvider *content = gdk_clipboard_get_content (clipboard);
GValue value = G_VALUE_INIT;
GdkPaintable *paintable;
GType type;
g_value_init (&value, GDK_TYPE_PAINTABLE);
if (!gdk_content_provider_get_value (content, &value, NULL))
return;
if (gdk_content_formats_contain_gtype (gdk_clipboard_get_formats (clipboard), GDK_TYPE_TEXTURE))
type = GDK_TYPE_TEXTURE;
else
type = GDK_TYPE_PAINTABLE;
paintable = GDK_PAINTABLE (g_value_get_object (&value));
gtk_image_set_from_paintable (GTK_IMAGE (demo->image), paintable);
g_value_unset (&value);
gdk_clipboard_read_value_async (clipboard,
type,
G_PRIORITY_DEFAULT,
NULL,
paste_image_cb,
g_object_ref (widget));
}
static void

View File

@@ -131,6 +131,19 @@ insert_tags_for_attributes (GtkTextBuffer *buffer,
gtk_text_buffer_apply_tag (buffer, tag, start, end); \
}
#define VOID_ATTR(attr_name) \
{ \
tag = gtk_text_tag_table_lookup (table, #attr_name); \
if (!tag) \
{ \
tag = gtk_text_tag_new (#attr_name); \
g_object_set (tag, #attr_name, TRUE, NULL); \
gtk_text_tag_table_add (table, tag); \
g_object_unref (tag); \
} \
gtk_text_buffer_apply_tag (buffer, tag, start, end); \
}
fg_alpha = bg_alpha = 1.;
attrs = pango_attr_iterator_get_attrs (iter);
@@ -255,6 +268,29 @@ insert_tags_for_attributes (GtkTextBuffer *buffer,
INT_ATTR (insert_hyphens);
break;
case PANGO_ATTR_LINE_HEIGHT:
FLOAT_ATTR (line_height);
break;
case PANGO_ATTR_ABSOLUTE_LINE_HEIGHT:
break;
case PANGO_ATTR_WORD:
VOID_ATTR (word);
break;
case PANGO_ATTR_SENTENCE:
VOID_ATTR (sentence);
break;
case PANGO_ATTR_BASELINE_SHIFT:
INT_ATTR (baseline_shift);
break;
case PANGO_ATTR_FONT_SCALE:
INT_ATTR (font_scale);
break;
case PANGO_ATTR_SHAPE:
case PANGO_ATTR_ABSOLUTE_SIZE:
case PANGO_ATTR_GRAVITY:
@@ -263,6 +299,10 @@ insert_tags_for_attributes (GtkTextBuffer *buffer,
case PANGO_ATTR_BACKGROUND_ALPHA:
break;
case PANGO_ATTR_TEXT_TRANSFORM:
INT_ATTR (text_transform);
break;
case PANGO_ATTR_INVALID:
default:
g_assert_not_reached ();

View File

@@ -1,6 +1,11 @@
/* Pango/Font Rendering
*
* Demonstrates various aspects of font rendering.
* Demonstrates various aspects of font rendering,
* such as hinting, antialiasing and grid alignment.
*
* The demo lets you explore font rendering options
* interactively to get a feeling for they affect the
* shape and positioning of the glyphs.
*/
#include <gtk/gtk.h>
@@ -10,16 +15,21 @@ static GtkWidget *font_button = NULL;
static GtkWidget *entry = NULL;
static GtkWidget *image = NULL;
static GtkWidget *hinting = NULL;
static GtkWidget *anti_alias = NULL;
static GtkWidget *hint_metrics = NULL;
static GtkWidget *up_button = NULL;
static GtkWidget *down_button = NULL;
static GtkWidget *text_radio = NULL;
static GtkWidget *show_grid = NULL;
static GtkWidget *show_extents = NULL;
static GtkWidget *show_pixels = NULL;
static GtkWidget *show_outlines = NULL;
static PangoContext *context;
static int scale = 9;
static int scale = 7;
static double pixel_alpha = 1.0;
static double outline_alpha = 0.0;
static void
update_image (void)
@@ -27,7 +37,7 @@ update_image (void)
const char *text;
PangoFontDescription *desc;
PangoLayout *layout;
PangoRectangle ink, pink, logical;
PangoRectangle ink, logical;
int baseline;
cairo_surface_t *surface;
cairo_t *cr;
@@ -37,6 +47,8 @@ update_image (void)
cairo_font_options_t *fopt;
cairo_hint_style_t hintstyle;
cairo_hint_metrics_t hintmetrics;
cairo_antialias_t antialias;
cairo_path_t *path;
if (!context)
context = gtk_widget_create_pango_context (image);
@@ -65,6 +77,13 @@ update_image (void)
hintmetrics = CAIRO_HINT_METRICS_OFF;
cairo_font_options_set_hint_metrics (fopt, hintmetrics);
if (gtk_check_button_get_active (GTK_CHECK_BUTTON (anti_alias)))
antialias = CAIRO_ANTIALIAS_GRAY;
else
antialias = CAIRO_ANTIALIAS_NONE;
cairo_font_options_set_antialias (fopt, antialias);
pango_context_set_round_glyph_positions (context, hintmetrics == CAIRO_HINT_METRICS_ON);
pango_cairo_context_set_font_options (context, fopt);
cairo_font_options_destroy (fopt);
pango_context_changed (context);
@@ -75,7 +94,6 @@ update_image (void)
pango_layout_set_font_description (layout, desc);
pango_layout_set_text (layout, text, -1);
pango_layout_get_extents (layout, &ink, &logical);
pink = ink;
baseline = pango_layout_get_baseline (layout);
pango_extents_to_pixels (&ink, NULL);
@@ -85,10 +103,14 @@ update_image (void)
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_paint (cr);
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_set_source_rgba (cr, 0, 0, 0, pixel_alpha);
cairo_move_to (cr, 10, 10);
pango_cairo_show_layout (cr, layout);
pango_cairo_layout_path (cr, layout);
path = cairo_copy_path (cr);
cairo_destroy (cr);
g_object_unref (layout);
@@ -127,7 +149,7 @@ update_image (void)
if (gtk_check_button_get_active (GTK_CHECK_BUTTON (show_extents)))
{
cairo_set_source_rgba (cr, 0, 0, 1, 1);
cairo_set_source_rgb (cr, 0, 0, 1);
cairo_rectangle (cr,
scale * (10 + pango_units_to_double (logical.x)) - 0.5,
@@ -140,17 +162,45 @@ update_image (void)
cairo_line_to (cr, scale * (10 + pango_units_to_double (logical.x + logical.width)) + 1,
scale * (10 + pango_units_to_double (baseline)) - 0.5);
cairo_stroke (cr);
cairo_set_source_rgba (cr, 1, 0, 0, 1);
cairo_set_source_rgb (cr, 1, 0, 0);
cairo_rectangle (cr,
scale * (10 + pango_units_to_double (pink.x)) + 0.5,
scale * (10 + pango_units_to_double (pink.y)) + 0.5,
scale * pango_units_to_double (pink.width) - 1,
scale * pango_units_to_double (pink.height) - 1);
scale * (10 + ink.x) - 0.5,
scale * (10 + ink.y) - 0.5,
scale * ink.width + 1,
scale * ink.height + 1);
cairo_stroke (cr);
}
for (int i = 0; i < path->num_data; i += path->data[i].header.length)
{
cairo_path_data_t *data = &path->data[i];
switch (data->header.type)
{
case CAIRO_PATH_CURVE_TO:
data[3].point.x *= scale; data[3].point.y *= scale;
data[2].point.x *= scale; data[2].point.y *= scale;
data[1].point.x *= scale; data[1].point.y *= scale;
break;
case CAIRO_PATH_LINE_TO:
case CAIRO_PATH_MOVE_TO:
data[1].point.x *= scale; data[1].point.y *= scale;
break;
case CAIRO_PATH_CLOSE_PATH:
break;
default:
g_assert_not_reached ();
}
}
cairo_set_source_rgba (cr, 0, 0, 0, outline_alpha);
cairo_move_to (cr, scale * 20 - 0.5, scale * 20 - 0.5);
cairo_append_path (cr, path);
cairo_stroke (cr);
cairo_surface_destroy (surface);
cairo_destroy (cr);
cairo_path_destroy (path);
}
else
{
@@ -158,10 +208,26 @@ update_image (void)
PangoLayoutRun *run;
PangoGlyphInfo *g;
int i, j;
GString *str;
gunichar ch;
if (*text == '\0')
text = " ";
ch = g_utf8_get_char (text);
str = g_string_new ("");
for (i = 0; i < 4; i++)
{
g_string_append_unichar (str, ch);
g_string_append_unichar (str, 0x200c);
}
layout = pango_layout_new (context);
pango_layout_set_font_description (layout, desc);
pango_layout_set_text (layout, "aaaa", -1);
pango_layout_set_text (layout, str->str, -1);
g_string_free (str, TRUE);
pango_layout_get_extents (layout, &ink, &logical);
pango_extents_to_pixels (&logical, NULL);
@@ -176,7 +242,7 @@ update_image (void)
cairo_set_source_rgb (cr, 0, 0, 0);
for (i = 0; i < 4; i++)
{
g = &(run->glyphs->glyphs[i]);
g = &(run->glyphs->glyphs[2*i]);
g->geometry.width = PANGO_UNITS_ROUND (g->geometry.width * 3 / 2);
}
@@ -184,7 +250,7 @@ update_image (void)
{
for (i = 0; i < 4; i++)
{
g = &(run->glyphs->glyphs[i]);
g = &(run->glyphs->glyphs[2*i]);
g->geometry.x_offset = i * (PANGO_SCALE / 4);
g->geometry.y_offset = j * (PANGO_SCALE / 4);
}
@@ -203,7 +269,6 @@ update_image (void)
cairo_surface_destroy (surface);
}
gtk_picture_set_pixbuf (GTK_PICTURE (image), pixbuf2);
g_object_unref (pixbuf2);
@@ -211,6 +276,78 @@ update_image (void)
pango_font_description_free (desc);
}
static gboolean fading = FALSE;
static double start_pixel_alpha;
static double end_pixel_alpha;
static double start_outline_alpha;
static double end_outline_alpha;
static gint64 start_time;
static gint64 end_time;
static double
ease_out_cubic (double t)
{
double p = t - 1;
return p * p * p + 1;
}
static gboolean
change_alpha (GtkWidget *widget,
GdkFrameClock *clock,
gpointer user_data)
{
gint64 now = g_get_monotonic_time ();
double t;
t = ease_out_cubic ((now - start_time) / (double) (end_time - start_time));
pixel_alpha = start_pixel_alpha + (end_pixel_alpha - start_pixel_alpha) * t;
outline_alpha = start_outline_alpha + (end_outline_alpha - start_outline_alpha) * t;
update_image ();
if (now >= end_time)
{
fading = FALSE;
return G_SOURCE_REMOVE;
}
return G_SOURCE_CONTINUE;
}
static void
start_alpha_fade (void)
{
gboolean pixels;
gboolean outlines;
if (fading)
return;
pixels = gtk_check_button_get_active (GTK_CHECK_BUTTON (show_pixels));
outlines = gtk_check_button_get_active (GTK_CHECK_BUTTON (show_outlines));
start_pixel_alpha = pixel_alpha;
if (pixels && outlines)
end_pixel_alpha = 0.5;
else if (pixels)
end_pixel_alpha = 1;
else
end_pixel_alpha = 0;
start_outline_alpha = outline_alpha;
if (outlines)
end_outline_alpha = 1.0;
else
end_outline_alpha = 0.0;
start_time = g_get_monotonic_time ();
end_time = start_time + G_TIME_SPAN_SECOND / 2;
fading = TRUE;
gtk_widget_add_tick_callback (window, change_alpha, NULL, NULL);
}
static void
update_buttons (void)
{
@@ -218,20 +355,26 @@ update_buttons (void)
gtk_widget_set_sensitive (down_button, scale > 1);
}
static void
scale_up (void)
static gboolean
scale_up (GtkWidget *widget,
GVariant *args,
gpointer user_data)
{
scale += 1;
update_buttons ();
update_image ();
return TRUE;
}
static void
scale_down (void)
static gboolean
scale_down (GtkWidget *widget,
GVariant *args,
gpointer user_data)
{
scale -= 1;
update_buttons ();
update_image ();
return TRUE;
}
GtkWidget *
@@ -252,20 +395,26 @@ do_fontrendering (GtkWidget *do_widget)
entry = GTK_WIDGET (gtk_builder_get_object (builder, "entry"));
image = GTK_WIDGET (gtk_builder_get_object (builder, "image"));
hinting = GTK_WIDGET (gtk_builder_get_object (builder, "hinting"));
anti_alias = GTK_WIDGET (gtk_builder_get_object (builder, "antialias"));
hint_metrics = GTK_WIDGET (gtk_builder_get_object (builder, "hint_metrics"));
text_radio = GTK_WIDGET (gtk_builder_get_object (builder, "text_radio"));
show_grid = GTK_WIDGET (gtk_builder_get_object (builder, "show_grid"));
show_extents = GTK_WIDGET (gtk_builder_get_object (builder, "show_extents"));
show_pixels = GTK_WIDGET (gtk_builder_get_object (builder, "show_pixels"));
show_outlines = GTK_WIDGET (gtk_builder_get_object (builder, "show_outlines"));
g_signal_connect (up_button, "clicked", G_CALLBACK (scale_up), NULL);
g_signal_connect (down_button, "clicked", G_CALLBACK (scale_down), NULL);
g_signal_connect (entry, "notify::text", G_CALLBACK (update_image), NULL);
g_signal_connect (font_button, "notify::font-desc", G_CALLBACK (update_image), NULL);
g_signal_connect (hinting, "notify::active", G_CALLBACK (update_image), NULL);
g_signal_connect (anti_alias, "notify::active", G_CALLBACK (update_image), NULL);
g_signal_connect (hint_metrics, "notify::active", G_CALLBACK (update_image), NULL);
g_signal_connect (text_radio, "notify::active", G_CALLBACK (update_image), NULL);
g_signal_connect (show_grid, "notify::active", G_CALLBACK (update_image), NULL);
g_signal_connect (show_extents, "notify::active", G_CALLBACK (update_image), NULL);
g_signal_connect (show_pixels, "notify::active", G_CALLBACK (start_alpha_fade), NULL);
g_signal_connect (show_outlines, "notify::active", G_CALLBACK (start_alpha_fade), NULL);
update_image ();

View File

@@ -1,13 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkAdjustment" id="scale_adj">
<property name="upper">24</property>
<property name="step-increment">1</property>
<property name="page-increment">4</property>
</object>
<object class="GtkWindow" id="window">
<property name="default-width">1080</property>
<property name="default-height">430</property>
<property name="default-width">1024</property>
<property name="default-height">768</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<child type="title">
@@ -87,35 +82,62 @@
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Hinting</property>
<property name="xalign">1</property>
<style>
<class name="dim-label"/>
</style>
<object class="GtkCheckButton" id="show_pixels">
<property name="label">Show _Pixels</property>
<property name="use-underline">1</property>
<property name="active">1</property>
<layout>
<property name="column">3</property>
<property name="row">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkComboBoxText" id="hinting">
<property name="active">0</property>
<property name="valign">center</property>
<items>
<item translatable="yes" id="none">None</item>
<item translatable="yes" id="slight">Slight</item>
<item translatable="yes" id="medium">Medium</item>
<item translatable="yes" id="full">Full</item>
</items>
<object class="GtkCheckButton" id="show_outlines">
<property name="label">Show _Outline</property>
<property name="use-underline">1</property>
<layout>
<property name="column">3</property>
<property name="row">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkBox">
<property name="spacing">6</property>
<child>
<object class="GtkLabel">
<property name="label">_Hinting</property>
<property name="use-underline">1</property>
<property name="mnemonic-widget">hinting</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkComboBoxText" id="hinting">
<property name="active">0</property>
<property name="valign">center</property>
<items>
<item translatable="yes" id="none">None</item>
<item translatable="yes" id="slight">Slight</item>
<item translatable="yes" id="medium">Medium</item>
<item translatable="yes" id="full">Full</item>
</items>
</object>
</child>
<layout>
<property name="column">4</property>
<property name="column-span">2</property>
</layout>
</object>
</child>
<child>
<object class="GtkCheckButton" id="hint_metrics">
<property name="label">Hint Metrics</property>
<object class="GtkCheckButton" id="antialias">
<property name="label">_Antialias</property>
<property name="use-underline">1</property>
<property name="active">1</property>
<layout>
<property name="column">4</property>
<property name="row">1</property>
@@ -123,21 +145,31 @@
</object>
</child>
<child>
<object class="GtkCheckButton" id="show_extents">
<property name="label">Show Extents</property>
<property name="active">1</property>
<object class="GtkCheckButton" id="hint_metrics">
<property name="label">Hint _Metrics</property>
<property name="use-underline">1</property>
<layout>
<property name="column">5</property>
<property name="row">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkCheckButton" id="show_extents">
<property name="label">Show _Extents</property>
<property name="use-underline">1</property>
<layout>
<property name="column">6</property>
<property name="row">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkCheckButton" id="show_grid">
<property name="active">1</property>
<property name="label">Show Grid</property>
<property name="label">Show _Grid</property>
<property name="use-underline">1</property>
<layout>
<property name="column">5</property>
<property name="column">6</property>
<property name="row">1</property>
</layout>
</object>
@@ -145,11 +177,24 @@
<child>
<object class="GtkButton" id="up_button">
<property name="icon-name">list-add-symbolic</property>
<property name="halign">center</property>
<property name="valign">center</property>
<style>
<class name="circular"/>
</style>
<child>
<object class="GtkShortcutController">
<property name="scope">managed</property>
<child>
<object class="GtkShortcut">
<property name="trigger">&lt;Control&gt;plus</property>
<property name="action">activate</property>
</object>
</child>
</object>
</child>
<layout>
<property name="column">6</property>
<property name="column">7</property>
<property name="row">0</property>
</layout>
</object>
@@ -157,11 +202,24 @@
<child>
<object class="GtkButton" id="down_button">
<property name="icon-name">list-remove-symbolic</property>
<property name="halign">center</property>
<property name="valign">center</property>
<style>
<class name="circular"/>
</style>
<child>
<object class="GtkShortcutController">
<property name="scope">managed</property>
<child>
<object class="GtkShortcut">
<property name="trigger">&lt;Control&gt;minus</property>
<property name="action">activate</property>
</object>
</child>
</object>
</child>
<layout>
<property name="column">6</property>
<property name="column">7</property>
<property name="row">1</property>
</layout>
</object>
@@ -170,7 +228,7 @@
<object class="GtkLabel">
<property name="hexpand">1</property>
<layout>
<property name="column">7</property>
<property name="column">8</property>
</layout>
</object>
</child>

View File

@@ -61,12 +61,26 @@ show_page (GtkTextView *text_view,
int page)
{
GtkTextBuffer *buffer;
GtkTextIter iter;
GtkTextIter iter, start;
GtkTextMark *mark;
GtkWidget *child;
GtkTextChildAnchor *anchor;
GtkEventController *controller;
GtkTextTag *bold, *mono, *nobreaks;
buffer = gtk_text_view_get_buffer (text_view);
bold = gtk_text_buffer_create_tag (buffer, NULL,
"weight", PANGO_WEIGHT_BOLD,
"scale", PANGO_SCALE_X_LARGE,
NULL);
mono = gtk_text_buffer_create_tag (buffer, NULL,
"family", "monospace",
NULL);
nobreaks = gtk_text_buffer_create_tag (buffer, NULL,
"allow-breaks", FALSE,
NULL);
gtk_text_buffer_set_text (buffer, "", 0);
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
gtk_text_buffer_begin_irreversible_action (buffer);
@@ -104,17 +118,22 @@ show_page (GtkTextView *text_view,
}
else if (page == 2)
{
GtkTextTag *tag;
mark = gtk_text_buffer_create_mark (buffer, "mark", &iter, TRUE);
tag = gtk_text_buffer_create_tag (buffer, NULL,
"weight", PANGO_WEIGHT_BOLD,
"scale", PANGO_SCALE_X_LARGE,
NULL);
gtk_text_buffer_insert_with_tags (buffer, &iter, "tag", -1, tag, NULL);
tag = gtk_text_buffer_create_tag (buffer, NULL,
"family", "monospace",
NULL);
gtk_text_buffer_insert_with_tags (buffer, &iter, " /tag/ ", -1, tag, NULL);
gtk_text_buffer_insert_with_tags (buffer, &iter, "tag", -1, bold, NULL);
gtk_text_buffer_insert (buffer, &iter, " /", -1);
gtk_text_buffer_get_iter_at_mark (buffer, &start, mark);
gtk_text_buffer_apply_tag (buffer, nobreaks, &start, &iter);
gtk_text_buffer_insert (buffer, &iter, " ", -1);
gtk_text_buffer_move_mark (buffer, mark, &iter);
gtk_text_buffer_insert_with_tags (buffer, &iter, "tag", -1, mono, NULL);
gtk_text_buffer_insert (buffer, &iter, " /", -1);
gtk_text_buffer_get_iter_at_mark (buffer, &start, mark);
gtk_text_buffer_apply_tag (buffer, nobreaks, &start, &iter);
gtk_text_buffer_insert (buffer, &iter, " ", -1);
anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
child = gtk_image_new_from_icon_name ("audio-volume-high-symbolic");
@@ -132,20 +151,26 @@ show_page (GtkTextView *text_view,
"behavior of mouse and key presses, “lock” a range of text so the "
"user can't edit it, or countless other things.\n", -1);
insert_link (buffer, &iter, "Go back", 1);
gtk_text_buffer_delete_mark (buffer, mark);
}
else if (page == 3)
{
GtkTextTag *tag;
mark = gtk_text_buffer_create_mark (buffer, "mark", &iter, TRUE);
tag = gtk_text_buffer_create_tag (buffer, NULL,
"weight", PANGO_WEIGHT_BOLD,
"scale", PANGO_SCALE_X_LARGE,
NULL);
gtk_text_buffer_insert_with_tags (buffer, &iter, "hypertext", -1, tag, NULL);
tag = gtk_text_buffer_create_tag (buffer, NULL,
"family", "monospace",
NULL);
gtk_text_buffer_insert_with_tags (buffer, &iter, " /ˈhaɪ pərˌtɛkst/ ", -1, tag, NULL);
gtk_text_buffer_insert_with_tags (buffer, &iter, "hypertext", -1, bold, NULL);
gtk_text_buffer_insert (buffer, &iter, " /", -1);
gtk_text_buffer_get_iter_at_mark (buffer, &start, mark);
gtk_text_buffer_apply_tag (buffer, nobreaks, &start, &iter);
gtk_text_buffer_insert (buffer, &iter, " ", -1);
gtk_text_buffer_move_mark (buffer, mark, &iter);
gtk_text_buffer_insert_with_tags (buffer, &iter, "ˈhaɪ pərˌtɛkst", -1, mono, NULL);
gtk_text_buffer_insert (buffer, &iter, " /", -1);
gtk_text_buffer_get_iter_at_mark (buffer, &start, mark);
gtk_text_buffer_apply_tag (buffer, nobreaks, &start, &iter);
gtk_text_buffer_insert (buffer, &iter, " ", -1);
anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
child = gtk_image_new_from_icon_name ("audio-volume-high-symbolic");
@@ -159,6 +184,8 @@ show_page (GtkTextView *text_view,
"Machine-readable text that is not sequential but is organized "
"so that related items of information are connected.\n", -1);
insert_link (buffer, &iter, "Go back", 1);
gtk_text_buffer_delete_mark (buffer, mark);
}
gtk_text_buffer_end_irreversible_action (buffer);
}
@@ -358,7 +385,7 @@ do_hypertext (GtkWidget *do_widget)
sw = gtk_scrolled_window_new ();
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_NEVER,
GTK_POLICY_AUTOMATIC);
gtk_window_set_child (GTK_WINDOW (window), sw);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), view);

View File

@@ -8,7 +8,7 @@
#include <stdlib.h>
#include <string.h>
static GdkPixbuf *avatar_pixbuf_other;
static GdkTexture *avatar_texture_other;
static GtkWidget *window = NULL;
#define GTK_TYPE_MESSAGE (gtk_message_get_type ())
@@ -196,12 +196,9 @@ gtk_message_row_update (GtkMessageRow *row)
gtk_button_set_label (GTK_BUTTON (priv->resent_by_button), priv->message->resent_by);
if (strcmp (priv->message->sender_nick, "@GTKtoolkit") == 0)
{
gtk_image_set_from_icon_name (priv->avatar_image, "org.gtk.Demo4");
gtk_image_set_icon_size (priv->avatar_image, GTK_ICON_SIZE_LARGE);
}
gtk_image_set_from_icon_name (priv->avatar_image, "org.gtk.Demo4");
else
gtk_image_set_from_pixbuf (priv->avatar_image, avatar_pixbuf_other);
gtk_image_set_from_paintable (priv->avatar_image, GDK_PAINTABLE (avatar_texture_other));
}
@@ -344,7 +341,7 @@ do_listbox (GtkWidget *do_widget)
if (!window)
{
avatar_pixbuf_other = gdk_pixbuf_new_from_resource_at_scale ("/listbox/apple-red.png", 32, 32, FALSE, NULL);
avatar_texture_other = gdk_texture_new_from_resource ("/listbox/apple-red.png");
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window),

View File

@@ -25,6 +25,7 @@
<property name="margin-start">8</property>
<property name="margin-end">8</property>
<property name="icon-name">image-missing</property>
<property name="icon-size">large</property>
<layout>
<property name="column">0</property>
<property name="row">0</property>

View File

@@ -58,7 +58,7 @@ do_markup (GtkWidget *do_widget)
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_default_size (GTK_WINDOW (window), 450, 450);
gtk_window_set_default_size (GTK_WINDOW (window), 600, 680);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
stack = gtk_stack_new ();

View File

@@ -1,5 +1,9 @@
Text sizes: <span size="xx-small">tiny</span> <span size="x-small">very small</span> <span size="small">small</span> <span size="medium">normal</span> <span size="large">large</span> <span size="x-large">very large</span> <span size="xx-large">huge</span>
Text sizes: <span size="xx-small">tiny </span><span size="x-small">very small </span><span size="small">small </span><span size="medium">normal </span><span size="large">large </span><span size="x-large">very large </span><span size="xx-large">huge</span>
Text styles: <span style="normal">Normal</span> <span style="italic">Italic</span> <span style="oblique">Olique</span>
Text weights: <span weight="thin">thin</span> <span weight="light">light</span> <span weight="normal">normal</span> <span weight="bold">bold</span> <span weight="ultraheavy">ultraheavy</span>
Text <span color="gray">c<span color="green">o</span>l<span color="tomato">o</span>rs</span> and <span background="pink">backgrounds</span>
@@ -15,6 +19,12 @@ OpenType font features: <span font_desc="sans regular" font_features="dlig=0">fe
Shortcuts: <tt>Monospace</tt> <b>Bold</b> <i>Italic</i> <big>Big</big> <small>Small</small> <u>Underlined</u> <s>Strikethrough</s> Super<sup>script</sup> Sub<sub>script</sub>
<span allow_breaks="false">A</span> hy­phen­ation al­go­rithm is a set of rules, espe­ci­ally one co­di­fied for im­ple­men­tation in a com­pu­ter pro­gram, that de­ci­des at which points a word can be bro­ken over two lines with a hy­phen. For ex­am­ple, a hy­phen­ation al­go­rithm might de­cide that im­peach­ment can be broken as <span allow_breaks="false">impeach‧ment</span> or <span allow_breaks="false">im‧peachment</span> but not <span allow_breaks="false">impe‧achment.</span>
hy­phen­ation al­go­rithm is a <span allow_breaks="false" style="italic">set of rules</span>, espe­ci­ally one co­di­fied for im­ple­men­tation in a com­pu­ter pro­gram, that de­ci­des at which points a word can be bro­ken over two lines with a hy­phen. For ex­am­ple, a hy­phen­ation al­go­rithm might de­cide that im­peach­ment can be broken as impeach‧ment or im‧peachment but not impe‧achment.
<span insert_hyphens="false">one/two three/four five/six seven/eight nine/ten</span>
<span line_height='1.33'>Line height: This is an example of widely spaced text. It was achieved by setting the line-height factor to 1.33. You can set the line-height factor to any value between 0 and 10.
Note that the line height affects the spacing between paragraphs as well as between the wrapped lines inside a paragraph.</span>
Transforms: <span text_transform='uppercase'>straße</span> <span text_transform='capitalize'>up, up and away</span>

View File

@@ -21,8 +21,10 @@ do_menu (GtkWidget *do_widget)
if (!window)
{
GtkWidget *box;
GtkWidget *sw;
GtkWidget *widget;
GtkWidget *scale;
window = gtk_window_new ();
gtk_window_set_title (GTK_WINDOW (window), "Menu");
@@ -31,11 +33,23 @@ do_menu (GtkWidget *do_widget)
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);
sw = gtk_scrolled_window_new ();
gtk_window_set_child (GTK_WINDOW (window), sw);
gtk_widget_set_vexpand (sw, TRUE);
gtk_box_append (GTK_BOX (box), sw);
widget = demo3_widget_new ("/transparent/portland-rose.jpg");
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), widget);
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_box_append (GTK_BOX (box), scale);
g_object_bind_property (gtk_range_get_adjustment (GTK_RANGE (scale)), "value",
widget, "scale",
G_BINDING_BIDIRECTIONAL);
}
if (!gtk_widget_get_visible (window))

View File

@@ -67,6 +67,7 @@ demos = files([
'paintable_animated.c',
'paintable_emblem.c',
'paintable_mediastream.c',
'paintable_symbolic.c',
'panes.c',
'password_entry.c',
'peg_solitaire.c',

View File

@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<id>org.gtk.Demo4.desktop</id>
<id>org.gtk.Demo4</id>
<launchable type="desktop-id">org.gtk.Demo4.desktop</launchable>
<metadata_license>CC0-1.0</metadata_license>
<project_license>LGPL-2.0+</project_license>
<project_license>LGPL-2.1-or-later</project_license>
<name>GTK Demo</name>
<summary>Program to demonstrate GTK functions</summary>
<description>
@@ -30,6 +31,7 @@
<translation type="gettext">gtk-4.0</translation>
<update_contact>matthias.clasen_at_gmail.com</update_contact>
<developer_name>Matthias Clasen and others</developer_name>
<content_rating type="oars-1.1"/>
<releases>
<release version="@BUILD_VERSION@" date="@BUILD_DATE@">
<description>

View File

@@ -45,26 +45,27 @@ struct _GtkNuclearIconClass
* so that it can be called from all the other demos, too.
*/
void
gtk_nuclear_snapshot (GtkSnapshot *snapshot,
double width,
double height,
double rotation,
gboolean draw_background)
gtk_nuclear_snapshot (GtkSnapshot *snapshot,
const GdkRGBA *foreground,
const GdkRGBA *background,
double width,
double height,
double rotation)
{
#define RADIUS 0.3
cairo_t *cr;
double size;
if (draw_background)
gtk_snapshot_append_color (snapshot,
&(GdkRGBA) { 0.9, 0.75, 0.15, 1.0 },
&GRAPHENE_RECT_INIT (0, 0, width, height));
gtk_snapshot_append_color (snapshot,
background,
&GRAPHENE_RECT_INIT (0, 0, width, height));
size = MIN (width, height);
cr = gtk_snapshot_append_cairo (snapshot,
&GRAPHENE_RECT_INIT ((width - size) / 2.0,
(height - size) / 2.0,
size, size));
gdk_cairo_set_source_rgba (cr, foreground);
cairo_translate (cr, width / 2.0, height / 2.0);
cairo_scale (cr, size, size);
cairo_rotate (cr, rotation);
@@ -94,9 +95,10 @@ gtk_nuclear_icon_snapshot (GdkPaintable *paintable,
*/
gtk_nuclear_snapshot (snapshot,
&(GdkRGBA) { 0, 0, 0, 1 }, /* black */
&(GdkRGBA) { 0.9, 0.75, 0.15, 1.0 }, /* yellow */
width, height,
nuclear->rotation,
TRUE);
nuclear->rotation);
}
static GdkPaintableFlags

View File

@@ -4,10 +4,11 @@
#include <gtk/gtk.h>
void gtk_nuclear_snapshot (GtkSnapshot *snapshot,
const GdkRGBA *foreground,
const GdkRGBA *background,
double width,
double height,
double rotation,
gboolean draw_background);
double rotation);
GdkPaintable * gtk_nuclear_icon_new (double rotation);
GdkPaintable * gtk_nuclear_animation_new (gboolean draw_background);

View File

@@ -65,9 +65,12 @@ gtk_nuclear_animation_snapshot (GdkPaintable *paintable,
/* We call the function from the previous example here. */
gtk_nuclear_snapshot (snapshot,
&(GdkRGBA) { 0, 0, 0, 1 }, /* black */
nuclear->draw_background
? &(GdkRGBA) { 0.9, 0.75, 0.15, 1.0 } /* yellow */
: &(GdkRGBA) { 0, 0, 0, 0 }, /* transparent */
width, height,
2 * G_PI * nuclear->progress / MAX_PROGRESS,
nuclear->draw_background);
2 * G_PI * nuclear->progress / MAX_PROGRESS);
}
static GdkPaintable *

View File

@@ -73,9 +73,10 @@ gtk_nuclear_media_stream_snapshot (GdkPaintable *paintable,
/* We call the function from the previous example here. */
gtk_nuclear_snapshot (snapshot,
&(GdkRGBA) { 0, 0, 0, 1 }, /* black */
&(GdkRGBA) { 0.9, 0.75, 0.15, 1.0 }, /* yellow */
width, height,
2 * G_PI * nuclear->progress / DURATION,
TRUE);
2 * G_PI * nuclear->progress / DURATION);
}
static GdkPaintable *

View File

@@ -0,0 +1,208 @@
/* Paintable/Symbolic Paintable
*
* GdkPaintables can be made to follow the theme's colors. GTK calls
* icons that do this symbolic icons, paintables that want to have
* the same effect can implement the GtkSymbolicPaintable interface.
*
* We will adapt the original paintable example by adding the ability
* to recolor the paintable based on the symbolic colors.
*/
#include <gtk/gtk.h>
#include "paintable.h"
static GtkWidget *window = NULL;
/* First, add the boilerplate for the object itself.
* This part would normally go in the header.
*/
#define GTK_TYPE_NUCLEAR_SYMBOLIC (gtk_nuclear_symbolic_get_type ())
G_DECLARE_FINAL_TYPE (GtkNuclearSymbolic, gtk_nuclear_symbolic, GTK, NUCLEAR_SYMBOLIC, GObject)
/* Declare a few warning levels, so we can pick colors based on them */
typedef enum
{
WARNING_NONE,
WARNING_ALERT,
WARNING_EMERGENCY
} WarningLevel;
/* Declare the struct. */
struct _GtkNuclearSymbolic
{
GObject parent_instance;
WarningLevel warning_level;
};
struct _GtkNuclearSymbolicClass
{
GObjectClass parent_class;
};
/* Add a function to draw the nuclear icon in the given colors */
static void
gtk_nuclear_symbolic_snapshot_symbolic (GtkSymbolicPaintable *paintable,
GdkSnapshot *snapshot,
double width,
double height,
const GdkRGBA *colors,
gsize n_colors)
{
GtkNuclearSymbolic *self = GTK_NUCLEAR_SYMBOLIC (paintable);
static const GdkRGBA transparent = { 0, };
const GdkRGBA *bg_color;
/* select the right background color from the warning level */
switch (self->warning_level)
{
case WARNING_NONE:
bg_color = &transparent;
break;
case WARNING_ALERT:
bg_color = &colors[GTK_SYMBOLIC_COLOR_WARNING];
break;
case WARNING_EMERGENCY:
bg_color = &colors[GTK_SYMBOLIC_COLOR_ERROR];
break;
default:
/* This should never happen, but we better do defensive coding
* with this critical icon */
g_assert_not_reached ();
bg_color = &transparent;
break;
}
/* Draw the icon with the selected warning color */
gtk_nuclear_snapshot (snapshot,
&colors[GTK_SYMBOLIC_COLOR_FOREGROUND],
bg_color,
width, height,
0);
}
static void
gtk_nuclear_symbolic_symbolic_paintable_init (GtkSymbolicPaintableInterface *iface)
{
iface->snapshot_symbolic = gtk_nuclear_symbolic_snapshot_symbolic;
}
/* We need to implement the functionality required by the GdkPaintable interface */
static void
gtk_nuclear_symbolic_snapshot (GdkPaintable *paintable,
GdkSnapshot *snapshot,
double width,
double height)
{
/* Calling this function without passing a color is a neat trick
* to make GTK use default colors and otherwise forward the call
* to the snapshotting function above.
*/
gtk_symbolic_paintable_snapshot_symbolic (GTK_SYMBOLIC_PAINTABLE (paintable),
snapshot,
width, height,
NULL, 0);
}
static GdkPaintableFlags
gtk_nuclear_symbolic_get_flags (GdkPaintable *paintable)
{
/* This image has a static size, but the contents may change:
* We draw different things when the warning level changes.
*/
return GDK_PAINTABLE_STATIC_SIZE;
}
static void
gtk_nuclear_symbolic_paintable_init (GdkPaintableInterface *iface)
{
iface->snapshot = gtk_nuclear_symbolic_snapshot;
iface->get_flags = gtk_nuclear_symbolic_get_flags;
}
/* When defining the GType, we need to implement bot the GdkPaintable
* and the GtkSymbolicPaintable interface */
G_DEFINE_TYPE_WITH_CODE (GtkNuclearSymbolic, gtk_nuclear_symbolic, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE,
gtk_nuclear_symbolic_paintable_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_SYMBOLIC_PAINTABLE,
gtk_nuclear_symbolic_symbolic_paintable_init))
static void
gtk_nuclear_symbolic_class_init (GtkNuclearSymbolicClass *klass)
{
}
static void
gtk_nuclear_symbolic_init (GtkNuclearSymbolic *nuclear)
{
}
/* And finally, we add the simple constructor we declared in the header. */
GdkPaintable *
gtk_nuclear_symbolic_new (void)
{
return g_object_new (GTK_TYPE_NUCLEAR_SYMBOLIC, NULL);
}
/* Add some fun feature to the button */
static void
nuclear_button_clicked (GtkButton *button,
GtkNuclearSymbolic *nuclear)
{
if (nuclear->warning_level >= WARNING_EMERGENCY)
{
/* On maximum warning level, reset the warning */
nuclear->warning_level = WARNING_NONE;
/* And sometimes (but not always to confuse people)
* close the window.
*/
if (g_random_boolean ())
gtk_window_close (GTK_WINDOW (window));
}
else
{
/* Otherwise just increase the warning level */
nuclear->warning_level++;
}
/* Don't forget to emit the signal causing the paintable to redraw.
* Changing the warning level changes the background color after all.
*/
gdk_paintable_invalidate_contents (GDK_PAINTABLE (nuclear));
}
GtkWidget *
do_paintable_symbolic (GtkWidget *do_widget)
{
GdkPaintable *nuclear;
GtkWidget *image, *button;
if (!window)
{
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Don't click!");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
button = gtk_button_new ();
gtk_window_set_child (GTK_WINDOW (window), button);
nuclear = gtk_nuclear_symbolic_new ();
image = gtk_image_new_from_paintable (nuclear);
gtk_button_set_child (GTK_BUTTON (button), image);
g_signal_connect (button, "clicked", G_CALLBACK (nuclear_button_clicked), nuclear);
g_object_unref (nuclear);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<id>org.gtk.IconBrowser4.desktop</id>
<id>org.gtk.IconBrowser4</id>
<launchable type="desktop-id">org.gtk.IconBrowser4.desktop</launchable>
<metadata_license>CC0-1.0</metadata_license>
<project_license>LGPL-2.0+</project_license>
<project_license>LGPL-2.1-or-later</project_license>
<name>GTK Icon Browser</name>
<summary>Program to browse themed icons</summary>
<description>
@@ -29,6 +30,7 @@
<translation type="gettext">gtk-4.0</translation>
<update_contact>matthias.clasen_at_gmail.com</update_contact>
<developer_name>Matthias Clasen and others</developer_name>
<content_rating type="oars-1.1"/>
<releases>
<release version="@BUILD_VERSION@" date="@BUILD_DATE@">
<description>

View File

@@ -24,7 +24,6 @@
#include "gtkrendererpaintableprivate.h"
#include "gsk/gskrendernodeparserprivate.h"
#include "gsk/gl/gskglrenderer.h"
#include "gsk/ngl/gsknglrenderer.h"
#ifdef GDK_WINDOWING_BROADWAY
#include "gsk/broadway/gskbroadwayrenderer.h"
@@ -61,7 +60,7 @@ struct _NodeEditorWindow
GtkWidget *renderer_listbox;
GListStore *renderers;
GdkPaintable *paintable;
GskRenderNode *node;
GFileMonitor *file_monitor;
@@ -168,7 +167,6 @@ static void
text_changed (GtkTextBuffer *buffer,
NodeEditorWindow *self)
{
GskRenderNode *node;
char *text;
GBytes *bytes;
GtkTextIter iter;
@@ -179,10 +177,12 @@ text_changed (GtkTextBuffer *buffer,
text_buffer_remove_all_tags (self->text_buffer);
bytes = g_bytes_new_take (text, strlen (text));
g_clear_pointer (&self->node, gsk_render_node_unref);
/* If this is too slow, go fix the parser performance */
node = gsk_render_node_deserialize (bytes, deserialize_error_func, self);
self->node = gsk_render_node_deserialize (bytes, deserialize_error_func, self);
g_bytes_unref (bytes);
if (node)
if (self->node)
{
/* XXX: Is this code necessary or can we have API to turn nodes into paintables? */
GtkSnapshot *snapshot;
@@ -191,10 +191,9 @@ text_changed (GtkTextBuffer *buffer,
guint i;
snapshot = gtk_snapshot_new ();
gsk_render_node_get_bounds (node, &bounds);
gsk_render_node_get_bounds (self->node, &bounds);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (- bounds.origin.x, - bounds.origin.y));
gtk_snapshot_append_node (snapshot, node);
gsk_render_node_unref (node);
gtk_snapshot_append_node (snapshot, self->node);
paintable = gtk_snapshot_free_to_paintable (snapshot, &bounds.size);
gtk_picture_set_paintable (GTK_PICTURE (self->picture), paintable);
for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (self->renderers)); i++)
@@ -338,15 +337,9 @@ text_view_query_tooltip_cb (GtkWidget *widget,
}
static gboolean
load_file_contents (NodeEditorWindow *self,
GFile *file)
load_bytes (NodeEditorWindow *self,
GBytes *bytes)
{
GBytes *bytes;
bytes = g_file_load_bytes (file, NULL, NULL, NULL);
if (bytes == NULL)
return FALSE;
if (!g_utf8_validate (g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes), NULL))
{
g_bytes_unref (bytes);
@@ -362,6 +355,105 @@ load_file_contents (NodeEditorWindow *self,
return TRUE;
}
static gboolean
load_file_contents (NodeEditorWindow *self,
GFile *file)
{
GBytes *bytes;
bytes = g_file_load_bytes (file, NULL, NULL, NULL);
if (bytes == NULL)
return FALSE;
return load_bytes (self, bytes);
}
static GdkContentProvider *
on_picture_drag_prepare_cb (GtkDragSource *source,
double x,
double y,
NodeEditorWindow *self)
{
if (self->node == NULL)
return NULL;
return gdk_content_provider_new_typed (GSK_TYPE_RENDER_NODE, self->node);
}
static void
on_picture_drop_read_done_cb (GObject *source,
GAsyncResult *res,
gpointer data)
{
NodeEditorWindow *self = data;
GOutputStream *stream = G_OUTPUT_STREAM (source);
GdkDrop *drop = g_object_get_data (source, "drop");
GdkDragAction action = 0;
GBytes *bytes;
if (g_output_stream_splice_finish (stream, res, NULL) >= 0)
{
bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (stream));
if (load_bytes (self, bytes))
action = GDK_ACTION_COPY;
}
g_object_unref (self);
gdk_drop_finish (drop, action);
g_object_unref (drop);
return;
}
static void
on_picture_drop_read_cb (GObject *source,
GAsyncResult *res,
gpointer data)
{
NodeEditorWindow *self = data;
GdkDrop *drop = GDK_DROP (source);
GInputStream *input;
GOutputStream *output;
input = gdk_drop_read_finish (drop, res, NULL, NULL);
if (input == NULL)
{
g_object_unref (self);
gdk_drop_finish (drop, 0);
return;
}
output = g_memory_output_stream_new_resizable ();
g_object_set_data (G_OBJECT (output), "drop", drop);
g_object_ref (drop);
g_output_stream_splice_async (output,
input,
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
G_PRIORITY_DEFAULT,
NULL,
on_picture_drop_read_done_cb,
self);
g_object_unref (output);
g_object_unref (input);
}
static gboolean
on_picture_drop_cb (GtkDropTargetAsync *dest,
GdkDrop *drop,
double x,
double y,
NodeEditorWindow *self)
{
gdk_drop_read_async (drop,
(const char *[2]) { "application/x-gtk-render-node", NULL },
G_PRIORITY_DEFAULT,
NULL,
on_picture_drop_read_cb,
g_object_ref (self));
return TRUE;
}
static void
file_changed_cb (GFileMonitor *monitor,
GFile *file,
@@ -736,6 +828,7 @@ node_editor_window_finalize (GObject *object)
g_array_free (self->errors, TRUE);
g_clear_pointer (&self->node, gsk_render_node_unref);
g_clear_object (&self->renderers);
G_OBJECT_CLASS (node_editor_window_parent_class)->finalize (object);
@@ -778,12 +871,9 @@ node_editor_window_realize (GtkWidget *widget)
NULL,
"Default");
#endif
node_editor_window_add_renderer (self,
gsk_gl_renderer_new (),
"OpenGL");
node_editor_window_add_renderer (self,
gsk_ngl_renderer_new (),
"NGL");
"OpenGL");
#ifdef GDK_RENDERING_VULKAN
node_editor_window_add_renderer (self,
gsk_vulkan_renderer_new (),
@@ -848,6 +938,8 @@ node_editor_window_class_init (NodeEditorWindowClass *class)
gtk_widget_class_bind_template_callback (widget_class, testcase_save_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, testcase_name_entry_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, dark_mode_cb);
gtk_widget_class_bind_template_callback (widget_class, on_picture_drag_prepare_cb);
gtk_widget_class_bind_template_callback (widget_class, on_picture_drop_cb);
}
static GtkWidget *

View File

@@ -198,8 +198,22 @@
<child>
<object class="GtkPicture" id="picture">
<property name="can-shrink">0</property>
<property name="keep-aspect-ratio">1</property>
<property name="halign">center</property>
<property name="valign">center</property>
<child>
<object class="GtkDragSource">
<property name="actions">copy</property>
<signal name="prepare" handler="on_picture_drag_prepare_cb" swapped="no"/>
</object>
</child>
</object>
</child>
<child>
<object class="GtkDropTargetAsync">
<property name="actions">copy</property>
<property name="formats">application/x-gtk-render-node</property>
<signal name="drop" handler="on_picture_drop_cb" swapped="no"/>
</object>
</child>
</object>

View File

@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<id>org.gtk.PrintEditor4.desktop</id>
<id>org.gtk.PrintEditor4</id>
<launchable type="desktop-id">org.gtk.PrintEditor4.desktop</launchable>
<metadata_license>CC0-1.0</metadata_license>
<project_license>LGPL-2.0+</project_license>
<project_license>LGPL-2.1-or-later</project_license>
<name>GTK Print Editor</name>
<summary>Program to demonstrate GTK printing</summary>
<description>
@@ -24,6 +25,7 @@
<translation type="gettext">gtk-4.0</translation>
<update_contact>matthias.clasen_at_gmail.com</update_contact>
<developer_name>Matthias Clasen and others</developer_name>
<content_rating type="oars-1.1"/>
<releases>
<release version="3.99.0" date="2020-07-30">
<description>

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<id>org.gtk.WidgetFactory4.desktop</id>
<id>org.gtk.WidgetFactory4</id>
<launchable type="desktop-id">org.gtk.WidgetFactory4.desktop</launchable>
<metadata_license>CC0-1.0</metadata_license>
<project_license>LGPL-2.0+</project_license>
<project_license>LGPL-2.1-or-later</project_license>
<name>GTK Widget Factory</name>
<summary>Program to demonstrate GTK functions</summary>
<description>
@@ -31,6 +32,7 @@
<translation type="gettext">gtk-4.0</translation>
<update_contact>matthias.clasen_at_gmail.com</update_contact>
<developer_name>Matthias Clasen and others</developer_name>
<content_rating type="oars-1.1"/>
<releases>
<release version="@BUILD_VERSION@" date="@BUILD_DATE@">
<description>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 MiB

After

Width:  |  Height:  |  Size: 59 KiB

View File

@@ -696,6 +696,37 @@ on_range_to_changed (GtkSpinButton *to)
gtk_spin_button_set_value (from, v2);
}
static GdkContentProvider *
on_picture_drag_prepare (GtkDragSource *source,
double x,
double y,
gpointer unused)
{
GtkWidget *picture;
picture = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (source));
return gdk_content_provider_new_typed (GDK_TYPE_TEXTURE, gtk_picture_get_paintable (GTK_PICTURE (picture)));
}
static gboolean
on_picture_drop (GtkDropTarget *dest,
const GValue *value,
double x,
double y,
gpointer unused)
{
GtkWidget *picture;
GdkPaintable *paintable;
picture = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest));
paintable = g_value_get_object (value);
gtk_picture_set_paintable (GTK_PICTURE (picture), paintable);
return TRUE;
}
static void
info_bar_response (GtkWidget *infobar, int response_id)
{
@@ -1182,7 +1213,7 @@ populate_flowbox (GtkWidget *flowbox)
GtkWidget *child;
int i;
const char *resources[] = {
"sunset.jpg", "snowy.jpg", "portland-rose.jpg"
"sunset.jpg", "portland-rose.jpg", "beach.jpg", "nyc.jpg"
};
if (GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (flowbox), "populated")))
@@ -2040,6 +2071,8 @@ activate (GApplication *app)
"on_page_combo_changed", (GCallback)on_page_combo_changed,
"on_range_from_changed", (GCallback)on_range_from_changed,
"on_range_to_changed", (GCallback)on_range_to_changed,
"on_picture_drag_prepare", (GCallback)on_picture_drag_prepare,
"on_picture_drop", (GCallback)on_picture_drop,
"tab_close_cb", (GCallback)tab_close_cb,
"increase_icon_size", (GCallback)increase_icon_size,
"decrease_icon_size", (GCallback)decrease_icon_size,

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gtk/WidgetFactory4">
<file preprocess="xml-stripblanks">widget-factory.ui</file>
<file alias='widget-factory.ui'>widget-factory.uic</file>
</gresource>
<gresource prefix="/org/gtk/WidgetFactory4">
<file>widget-factory.css</file>
@@ -115,7 +115,8 @@
<gresource prefix="/org/gtk/WidgetFactory4">
<file>gtk-logo.webm</file>
<file>sunset.jpg</file>
<file>snowy.jpg</file>
<file>portland-rose.jpg</file>
<file>nyc.jpg</file>
<file>beach.jpg</file>
</gresource>
</gresources>

View File

@@ -1051,22 +1051,9 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
<property name="spacing">10</property>
<property name="hexpand">1</property>
<child>
<object class="GtkFrame" id="frame1">
<property name="valign">start</property>
<child type="label">
<object class="GtkLabel" id="label1">
<property name="label" translatable="yes">&lt;b&gt;Video&lt;/b&gt;</property>
<property name="use-markup">1</property>
</object>
</child>
<object class="GtkFrame">
<child>
<object class="GtkVideo">
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
<property name="autoplay">1</property>
<property name="loop">1</property>
<property name="file">resource:///org/gtk/WidgetFactory4/gtk-logo.webm</property>
@@ -1075,66 +1062,78 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="vexpand">1</property>
<property name="hscrollbar-policy">never</property>
<property name="vscrollbar-policy">automatic</property>
<object class="GtkFrame">
<child type="label">
<object class="GtkLabel" id="label1">
<property name="label" translatable="yes">&lt;b&gt;Text Styles&lt;/b&gt;</property>
<property name="use-markup">1</property>
</object>
</child>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="spacing">10</property>
<object class="GtkScrolledWindow">
<property name="vexpand">1</property>
<property name="hscrollbar-policy">never</property>
<property name="vscrollbar-policy">automatic</property>
<property name="propagate-natural-height">1</property>
<property name="propagate-natural-width">1</property>
<child>
<object class="GtkLabel">
<property name="label">Large Title</property>
<style><class name="large-title"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Title 1</property>
<style><class name="title-1"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Title 2</property>
<style><class name="title-2"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Title 3</property>
<style><class name="title-3"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Title 4</property>
<style><class name="title-4"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Heading</property>
<style><class name="heading"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Body</property>
<style><class name="body"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Caption Heading</property>
<style><class name="caption-heading"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Caption</property>
<style><class name="caption"/></style>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="spacing">10</property>
<child>
<object class="GtkLabel">
<property name="label">Large Title</property>
<style><class name="large-title"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Title 1</property>
<style><class name="title-1"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Title 2</property>
<style><class name="title-2"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Title 3</property>
<style><class name="title-3"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Title 4</property>
<style><class name="title-4"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Heading</property>
<style><class name="heading"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Body</property>
<style><class name="body"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Caption Heading</property>
<style><class name="caption-heading"/></style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Caption</property>
<style><class name="caption"/></style>
</object>
</child>
</object>
</child>
</object>
@@ -1251,8 +1250,21 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
<child>
<object class="GtkNotebookPage">
<property name="child">
<object class="GtkBox" id="box6">
<property name="orientation">vertical</property>
<object class="GtkPicture">
<property name="file">resource:///org/gtk/WidgetFactory4/sunset.jpg</property>
<child>
<object class="GtkDragSource">
<property name="actions">copy</property>
<signal name="prepare" handler="on_picture_drag_prepare" swapped="no"/>
</object>
</child>
<child>
<object class="GtkDropTarget">
<property name="actions">copy</property>
<property name="formats">GdkTexture</property>
<signal name="drop" handler="on_picture_drop" swapped="no"/>
</object>
</child>
</object>
</property>
<property name="tab">
@@ -1265,8 +1277,21 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
<child>
<object class="GtkNotebookPage">
<property name="child">
<object class="GtkBox" id="box7">
<property name="orientation">vertical</property>
<object class="GtkPicture">
<property name="file">resource:///org/gtk/WidgetFactory4/nyc.jpg</property>
<child>
<object class="GtkDragSource">
<property name="actions">copy</property>
<signal name="prepare" handler="on_picture_drag_prepare" swapped="no"/>
</object>
</child>
<child>
<object class="GtkDropTarget">
<property name="actions">copy</property>
<property name="formats">GdkTexture</property>
<signal name="drop" handler="on_picture_drop" swapped="no"/>
</object>
</child>
</object>
</property>
<property name="tab">
@@ -1278,10 +1303,22 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
</child>
<child>
<object class="GtkNotebookPage">
<property name="position">2</property>
<property name="child">
<object class="GtkBox" id="box8">
<property name="orientation">vertical</property>
<object class="GtkPicture">
<property name="file">resource:///org/gtk/WidgetFactory4/beach.jpg</property>
<child>
<object class="GtkDragSource">
<property name="actions">copy</property>
<signal name="prepare" handler="on_picture_drag_prepare" swapped="no"/>
</object>
</child>
<child>
<object class="GtkDropTarget">
<property name="actions">copy</property>
<property name="formats">GdkTexture</property>
<signal name="drop" handler="on_picture_drop" swapped="no"/>
</object>
</child>
</object>
</property>
<property name="tab">
@@ -1299,7 +1336,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
<child>
<object class="GtkNotebookPage">
<property name="child">
<object class="GtkBox" id="box9">
<object class="GtkBox" id="box8">
<property name="orientation">vertical</property>
</object>
</property>

Binary file not shown.

View File

@@ -13,7 +13,7 @@ devhelp = true
[dependencies."GObject-2.0"]
name = "GObject"
description = "The base type system library"
docs_url = "https://developer.gnome.org/gobject/stable"
docs_url = "https://docs.gtk.org/gobject/"
[theme]
name = "basic"

View File

@@ -13,7 +13,7 @@ devhelp = true
[dependencies."GObject-2.0"]
name = "GObject"
description = "The base type system library"
docs_url = "https://developer.gnome.org/gobject/stable"
docs_url = "https://docs.gtk.org/gobject/"
[theme]
name = "basic"

View File

@@ -14,7 +14,7 @@ search_index = true
[dependencies."GObject-2.0"]
name = "GObject"
description = "The base type system library"
docs_url = "https://developer.gnome.org/gobject/stable"
docs_url = "https://docs.gtk.org/gobject/"
[dependencies."cairo-1.0"]
name = "Cairo"

View File

@@ -1,11 +1,15 @@
expand_content_md_files = [
]
gdk4_toml = configure_file(input: 'gdk4.toml.in', output: 'gdk4.toml', configuration: toml_conf)
gdk4x11_toml = configure_file(input: 'gdk4-x11.toml.in', output: 'gdk4-x11.toml', configuration: toml_conf)
gdk4wayland_toml = configure_file(input: 'gdk4-wayland.toml.in', output: 'gdk4-wayland.toml', configuration: toml_conf)
if get_option('gtk_doc')
gdk4_toml = configure_file(
input: 'gdk4.toml.in',
output: 'gdk4.toml',
configuration: toml_conf,
install: true,
install_dir: docs_dir / 'gdk4',
)
custom_target('gdk4-doc',
input: [ gdk4_toml, gdk_gir[0] ],
output: 'gdk4',
@@ -28,6 +32,14 @@ if get_option('gtk_doc')
)
if x11_enabled
gdk4x11_toml = configure_file(
input: 'gdk4-x11.toml.in',
output: 'gdk4-x11.toml',
configuration: toml_conf,
install: true,
install_dir: docs_dir / 'gdk4-x11',
)
custom_target('gdk4-x11-doc',
input: [ gdk4x11_toml, gdk_x11_gir[0] ],
output: 'gdk4-x11',
@@ -52,6 +64,14 @@ if get_option('gtk_doc')
endif
if wayland_enabled
gdk4wayland_toml = configure_file(
input: 'gdk4-wayland.toml.in',
output: 'gdk4-wayland.toml',
configuration: toml_conf,
install: true,
install_dir: docs_dir / 'gdk4-wayland',
)
custom_target('gdk4-wayland-doc',
input: [ gdk4wayland_toml, gdk_wayland_gir[0] ],
output: 'gdk4-wayland',

View File

@@ -3,11 +3,14 @@
// A map between namespaces and base URLs for their online documentation
baseURLs = [
[ 'Gdk', 'https://gnome.pages.gitlab.gnome.org/gtk/gdk4/' ],
[ 'GdkWayland', 'https://gnome.pages.gitlab.gnome.org/gtk/gdk4-wayland/' ],
[ 'GdkX11', 'https://gnome.pages.gitlab.gnome.org/gtk/gdk4-x11/' ],
[ 'Gsk', 'https://gnome.pages.gitlab.gnome.org/gtk/gsk4/' ],
[ 'Gtk', 'https://gnome.pages.gitlab.gnome.org/gtk/gtk4/' ],
[ 'Pango', 'https://gnome.pages/gitlab.gnome.org/pango/pango/' ],
[ 'PangoCairo', 'https://gnome.pages.gitlab.gnome.org/pango/pangocairo/' ],
[ 'GLib', 'https://docs.gtk.org/glib/' ],
[ 'GObject', 'https://docs.gtk.org/gobject/' ],
[ 'Gio', 'https://docs.gtk.org/gio/' ],
[ 'Gdk', 'https://docs.gtk.org/gdk4/' ],
[ 'GdkWayland', 'https://docs.gtk.org/gdk4-wayland/' ],
[ 'GdkX11', 'https://docs.gtk.org/gdk4-x11/' ],
[ 'Gsk', 'https://docs.gtk.org/gsk4/' ],
[ 'Gtk', 'https://docs.gtk.org/gtk4/' ],
[ 'Pango', 'https://docs.gtk.org/Pango/' ],
[ 'PangoCairo', 'https://docs.gtk.org/PangoCairo/' ],
]

View File

@@ -14,7 +14,7 @@ search_index = true
[dependencies."GObject-2.0"]
name = "GObject"
description = "The base type system library"
docs_url = "https://developer.gnome.org/gobject/stable/"
docs_url = "https://docs.gtk.org/gobject/"
[dependencies."Graphene-1.0"]
name = "Graphene"

View File

@@ -1,6 +1,12 @@
gsk4_toml = configure_file(input: 'gsk4.toml.in', output: 'gsk4.toml', configuration: toml_conf)
if get_option('gtk_doc')
gsk4_toml = configure_file(
input: 'gsk4.toml.in',
output: 'gsk4.toml',
configuration: toml_conf,
install: true,
install_dir: docs_dir / 'gsk4',
)
custom_target('gsk4-doc',
input: [ gsk4_toml, gsk_gir[0] ],
output: 'gsk4',

View File

@@ -3,11 +3,14 @@
// A map between namespaces and base URLs for their online documentation
baseURLs = [
[ 'Gdk', 'https://gnome.pages.gitlab.gnome.org/gtk/gdk4/' ],
[ 'GdkWayland', 'https://gnome.pages.gitlab.gnome.org/gtk/gdk4-wayland/' ],
[ 'GdkX11', 'https://gnome.pages.gitlab.gnome.org/gtk/gdk4-x11/' ],
[ 'Gsk', 'https://gnome.pages.gitlab.gnome.org/gtk/gsk4/' ],
[ 'Gtk', 'https://gnome.pages.gitlab.gnome.org/gtk/gtk4/' ],
[ 'Pango', 'https://gnome.pages/gitlab.gnome.org/pango/pango/' ],
[ 'PangoCairo', 'https://gnome.pages.gitlab.gnome.org/pango/pangocairo/' ],
[ 'GLib', 'https://docs.gtk.org/glib/' ],
[ 'GObject', 'https://docs.gtk.org/gobject/' ],
[ 'Gio', 'https://docs.gtk.org/gio/' ],
[ 'Gdk', 'https://docs.gtk.org/gdk4/' ],
[ 'GdkWayland', 'https://docs.gtk.org/gdk4-wayland/' ],
[ 'GdkX11', 'https://docs.gtk.org/gdk4-x11/' ],
[ 'Gsk', 'https://docs.gtk.org/gsk4/' ],
[ 'Gtk', 'https://docs.gtk.org/gtk4/' ],
[ 'Pango', 'https://docs.gtk.org/Pango/' ],
[ 'PangoCairo', 'https://docs.gtk.org/PangoCairo/' ],
]

View File

@@ -162,6 +162,8 @@ done with
|caret-color|[CSS Basic User Interface Level 3](https://www.w3.org/TR/css3-ui/#caret-color) | CSS allows an auto value |
|-gtk-secondary-caret-color|[Color](https://www.w3.org/TR/css-color-3/#valuea-def-color) | used for the secondary caret in bidirectional text |
|letter-spacing| [CSS Text Level 3](https://www.w3.org/TR/css3-text/#letter-spacing) | |
|text-transform| [CSS Text Level 3](https://www.w3.org/TR/css-text-3/#text-transform-property) | CSS allows full-width and full-size-kana. Since 4.6 |
|line-height| [CSS Inline Layout Level 3](https://www.w3.org/TR/css-inline-3/#line-height-property) | Since 4.6 |
|text-decoration-line| [CSS Text Decoration Level 3](https://www.w3.org/TR/css-text-decor-3/#text-decoration-line-property) | |
|text-decoration-color| [CSS Text Decoration Level 3](https://www.w3.org/TR/css-text-decor-3/#text-decoration-color-property) | |
|text-decoration-style| [CSS Text Decoration Level 3](https://www.w3.org/TR/css-text-decor-3/#text-decoration-style-property) | CSS allows dashed and dotted |

View File

@@ -14,7 +14,7 @@ search_index = true
[dependencies."GObject-2.0"]
name = "GObject"
description = "The base type system library"
docs_url = "https://developer.gnome.org/gobject/stable"
docs_url = "https://docs.gtk.org/gobject/"
[dependencies."Graphene-1.0"]
name = "Graphene"

View File

@@ -137,6 +137,14 @@ capture phase, and key bindings locally, during the target phase.
Under the hood, all shortcuts are represented as instances of `GtkShortcut`,
and they are managed by `GtkShortcutController`.
## Text input
When actual text input is needed (i.e. not just keyboard shortcuts),
input method support can be added to a widget by connecting an input
method context and listening to its `::commit` signal. To create a new
input method context, use gtk_im_multicontext_new(), to provide it with
input, use gtk_event_controller_key_set_im_context().
## Event controllers and gestures
Event controllers are standalone objects that can perform

View File

@@ -27,9 +27,15 @@ expand_content_md_files = [
'visual_index.md'
]
gtk4_toml = configure_file(input: 'gtk4.toml.in', output: 'gtk4.toml', configuration: toml_conf)
if get_option('gtk_doc')
gtk4_toml = configure_file(
input: 'gtk4.toml.in',
output: 'gtk4.toml',
configuration: toml_conf,
install: true,
install_dir: docs_dir / 'gtk4',
)
custom_target('gtk4-doc',
input: [ gtk4_toml, gtk_gir[0] ],
output: 'gtk4',

View File

@@ -3,11 +3,14 @@
// A map between namespaces and base URLs for their online documentation
baseURLs = [
[ 'Gdk', 'https://gnome.pages.gitlab.gnome.org/gtk/gdk4/' ],
[ 'GdkWayland', 'https://gnome.pages.gitlab.gnome.org/gtk/gdk4-wayland/' ],
[ 'GdkX11', 'https://gnome.pages.gitlab.gnome.org/gtk/gdk4-x11/' ],
[ 'Gsk', 'https://gnome.pages.gitlab.gnome.org/gtk/gsk4/' ],
[ 'Gtk', 'https://gnome.pages.gitlab.gnome.org/gtk/gtk4/' ],
[ 'Pango', 'https://gnome.pages/gitlab.gnome.org/pango/pango/' ],
[ 'PangoCairo', 'https://gnome.pages.gitlab.gnome.org/pango/pangocairo/' ],
[ 'GLib', 'https://docs.gtk.org/glib/' ],
[ 'GObject', 'https://docs.gtk.org/gobject/' ],
[ 'Gio', 'https://docs.gtk.org/gio/' ],
[ 'Gdk', 'https://docs.gtk.org/gdk4/' ],
[ 'GdkWayland', 'https://docs.gtk.org/gdk4-wayland/' ],
[ 'GdkX11', 'https://docs.gtk.org/gdk4-x11/' ],
[ 'Gsk', 'https://docs.gtk.org/gsk4/' ],
[ 'Gtk', 'https://docs.gtk.org/gtk4/' ],
[ 'Pango', 'https://docs.gtk.org/Pango/' ],
[ 'PangoCairo', 'https://docs.gtk.org/PangoCairo/' ],
]

View File

@@ -14,14 +14,19 @@ instructions, binary downloads, etc, can be found
The Win32 GDK backend can be influenced with some additional environment
variables.
### GDK_IGNORE_WINTAB
### GDK_WIN32_TABLET_INPUT_API
If this variable is set, GTK doesn't use the Wintab API for tablet support.
If this variable is set, it determines the API that GTK uses for tablet support.
The possible values are:
### GDK_USE_WINTAB
`none`
: Disables tablet support
If this variable is set, GTK uses the Wintab API for tablet support.
This is the default.
`wintab`
: Use the Wintab API
`winpointer`
: Use the Windows Pointer Input Stack API. This is the default.
## Windows-specific handling of cursors

View File

@@ -5,6 +5,10 @@ gidocgen = find_program('gi-docgen', required: get_option('gtk_doc'))
docs_dir = gtk_datadir / 'doc'
if get_option('gtk_doc') and not build_gir
error('API reference requires introspection.')
endif
subdir('gdk')
subdir('gsk')
subdir('gtk')

View File

@@ -603,8 +603,8 @@ bloat_pad_startup (GApplication *application)
g_object_unref (icon);
g_bytes_unref (bytes);
icon = G_ICON (gdk_pixbuf_new_from_resource ("/org/gtk/libgtk/icons/16x16/actions/folder-new.png", NULL));
item = g_menu_item_new ("Pixbuf", NULL);
icon = G_ICON (gdk_texture_new_from_resource ("/org/gtk/libgtk/icons/16x16/actions/folder-new.png"));
item = g_menu_item_new ("Texture", NULL);
g_menu_item_set_icon (item, icon);
g_menu_append_item (menu, item);
g_object_unref (item);

50
examples/labels.js Executable file
View File

@@ -0,0 +1,50 @@
#!/usr/bin/env -S GI_TYPELIB_PATH=${PWD}/build/gtk:${GI_TYPELIB_PATH} LD_PRELOAD=${LD_PRELOAD}:${PWD}/build/gtk/libgtk-4.so gjs
imports.gi.versions['Gtk'] = '4.0';
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const DemoWidget = GObject.registerClass({
GTypeName: 'DemoWidget',
}, class DemoWidget extends Gtk.Widget {
_init(params = {}) {
super._init(params);
let layout_manager = new Gtk.GridLayout ();
this.set_layout_manager (layout_manager);
this.label1 = new Gtk.Label({ label: "Red",
hexpand: true,
vexpand: true });
this.label1.set_parent (this);
let child1 = layout_manager.get_layout_child (this.label1);
child1.set_row (0);
child1.set_column (0);
this.label2 = new Gtk.Label({ label: "Green",
hexpand: true,
vexpand: true });
this.label2.set_parent (this);
let child2 = layout_manager.get_layout_child (this.label2);
child2.set_row (0);
child2.set_column (1);
}
});
// Create a new application
let app = new Gtk.Application({ application_id: 'org.gtk.exampleapp' });
// When the application is launched…
app.connect('activate', () => {
// … create a new window …
let win = new Gtk.ApplicationWindow({ application: app });
// … with a button in it …
let widget = new DemoWidget();
win.set_child(widget);
win.present();
});
// Run the application
app.run([]);

View File

@@ -33,6 +33,7 @@
#include "gdkinternals.h"
#include "gdkdeviceprivate.h"
#include <gdk/gdktextureprivate.h>
#include "gdk-private.h"
#include <glib.h>
#include <glib/gprintf.h>
@@ -463,7 +464,7 @@ gdk_broadway_display_flush_in_idle (GdkDisplay *display)
if (broadway_display->idle_flush_id == 0)
{
broadway_display->idle_flush_id = g_idle_add (flush_idle, g_object_ref (display));
g_source_set_name_by_id (broadway_display->idle_flush_id, "[gtk] flush_idle");
gdk_source_set_static_name_by_id (broadway_display->idle_flush_id, "[gtk] flush_idle");
}
}

View File

@@ -29,7 +29,7 @@ gboolean gdk_should_use_portal (void);
const char * gdk_get_startup_notification_id (void);
PangoDirection gdk_unichar_direction (gunichar ch);
PangoDirection gdk_unichar_direction (gunichar ch) G_GNUC_CONST;
PangoDirection gdk_find_base_dir (const char *text,
int len);
@@ -57,4 +57,11 @@ guint gdk_parse_debug_var (const char *variable,
# define g_memdup2(mem,size) g_memdup((mem),(size))
#endif
void gdk_source_set_static_name_by_id (guint tag,
const char *name);
#if !GLIB_CHECK_VERSION(2, 69, 1)
#define g_source_set_static_name(source, name) g_source_set_name ((source), (name))
#endif
#endif /* __GDK__PRIVATE_H__ */

View File

@@ -127,10 +127,12 @@ static const GdkDebugKey gdk_debug_keys[] = {
{ "gl-legacy", GDK_DEBUG_GL_LEGACY, "Use a legacy OpenGL context" },
{ "gl-gles", GDK_DEBUG_GL_GLES, "Use a GLES OpenGL context" },
{ "gl-debug", GDK_DEBUG_GL_DEBUG, "Insert debugging information in OpenGL" },
{ "gl-egl", GDK_DEBUG_GL_EGL, "Use EGL on X11 or Windows" },
{ "gl-glx", GDK_DEBUG_GL_GLX, "Use GLX on X11" },
{ "gl-wgl", GDK_DEBUG_GL_WGL, "Use WGL on Windows" },
{ "vulkan-disable", GDK_DEBUG_VULKAN_DISABLE, "Disable Vulkan support" },
{ "vulkan-validate", GDK_DEBUG_VULKAN_VALIDATE, "Load the Vulkan validation layer" },
{ "default-settings",GDK_DEBUG_DEFAULT_SETTINGS, "Force default values for xsettings" },
{ "default-settings",GDK_DEBUG_DEFAULT_SETTINGS, "Force default values for xsettings", TRUE },
};
@@ -412,3 +414,17 @@ gdk_find_base_dir (const char *text,
return dir;
}
void
gdk_source_set_static_name_by_id (guint tag,
const char *name)
{
GSource *source;
g_return_if_fail (tag > 0);
source = g_main_context_find_source_by_id (NULL, tag);
if (source == NULL)
return;
g_source_set_static_name (source, name);
}

View File

@@ -50,7 +50,7 @@ cairo_region_t *
gdk_cairo_region_create_from_surface
(cairo_surface_t *surface);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_6_FOR(gdk_gl_texture_new)
void gdk_cairo_draw_from_gl (cairo_t *cr,
GdkSurface *surface,
int source,

View File

@@ -635,7 +635,7 @@ gdk_clipboard_read_internal (GdkClipboard *clipboard,
/**
* gdk_clipboard_read_async:
* @clipboard: a `GdkClipboard`
* @mime_types: a %NULL-terminated array of mime types to choose from
* @mime_types: (array zero-terminated=1): a %NULL-terminated array of mime types to choose from
* @io_priority: the I/O priority of the request
* @cancellable: (nullable): optional `GCancellable` object
* @callback: (scope async): callback to call when the request is satisfied
@@ -1253,9 +1253,15 @@ gdk_clipboard_set_content (GdkClipboard *clipboard,
* @...: value contents conforming to @type
*
* Sets the clipboard to contain the value collected from the given varargs.
*
* Values should be passed the same way they are passed to other value
* collecting APIs, such as [`method@GObject.Object.set`] or
* [`id@g_signal_emit`].
*
* ```c
* gdk_clipboard_set (clipboard, GTK_TYPE_TEXT_BUFFER, buffer);
* gdk_clipboard_set (clipboard, GTK_TYPE_STRING, "Hello World");
*
* gdk_clipboard_set (clipboard, GDK_TYPE_TEXTURE, some_texture);
* ```
*/
void

View File

@@ -25,6 +25,8 @@
#include "filetransferportalprivate.h"
#include "gdktexture.h"
#include "gdkrgbaprivate.h"
#include "loaders/gdkpngprivate.h"
#include "loaders/gdktiffprivate.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
@@ -553,6 +555,8 @@ gdk_content_deserialize_async (GInputStream *stream,
Deserializer *deserializer;
g_return_if_fail (G_IS_INPUT_STREAM (stream));
g_return_if_fail (mime_type != NULL);
g_return_if_fail (G_TYPE_IS_VALUE_TYPE (type));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
g_return_if_fail (callback != NULL);
@@ -591,7 +595,10 @@ gdk_content_deserialize_finish (GAsyncResult *result,
g_return_val_if_fail (GDK_IS_CONTENT_DESERIALIZER (result), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
deserializer = GDK_CONTENT_DESERIALIZER (result);
g_return_val_if_fail (G_VALUE_HOLDS (value, G_VALUE_TYPE (&deserializer->value)), FALSE);
if (G_VALUE_TYPE (value) == 0)
g_value_init (value, G_VALUE_TYPE (&deserializer->value));
else
g_return_val_if_fail (G_VALUE_HOLDS (value, G_VALUE_TYPE (&deserializer->value)), FALSE);
if (deserializer->error)
{
@@ -650,6 +657,56 @@ pixbuf_deserializer (GdkContentDeserializer *deserializer)
deserializer);
}
static void
texture_deserializer_finish (GObject *source,
GAsyncResult *result,
gpointer deserializer)
{
GOutputStream *stream = G_OUTPUT_STREAM (source);
GBytes *bytes;
GError *error = NULL;
GdkTexture *texture = NULL;
gssize written;
written = g_output_stream_splice_finish (stream, result, &error);
if (written < 0)
{
gdk_content_deserializer_return_error (deserializer, error);
return;
}
bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (stream));
texture = gdk_texture_new_from_bytes (bytes, &error);
g_bytes_unref (bytes);
if (texture == NULL)
{
gdk_content_deserializer_return_error (deserializer, error);
return;
}
g_value_take_object (gdk_content_deserializer_get_value (deserializer), texture);
gdk_content_deserializer_return_success (deserializer);
}
static void
texture_deserializer (GdkContentDeserializer *deserializer)
{
GOutputStream *output;
output = g_memory_output_stream_new_resizable ();
g_output_stream_splice_async (output,
gdk_content_deserializer_get_input_stream (deserializer),
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE
| G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
gdk_content_deserializer_get_priority (deserializer),
gdk_content_deserializer_get_cancellable (deserializer),
texture_deserializer_finish,
deserializer);
g_object_unref (output);
}
static void
string_deserializer_finish (GObject *source,
GAsyncResult *result,
@@ -858,48 +915,71 @@ init (void)
initialized = TRUE;
gdk_content_register_deserializer ("image/png",
GDK_TYPE_TEXTURE,
texture_deserializer,
NULL,
NULL);
gdk_content_register_deserializer ("image/tiff",
GDK_TYPE_TEXTURE,
texture_deserializer,
NULL,
NULL);
gdk_content_register_deserializer ("image/jpeg",
GDK_TYPE_TEXTURE,
texture_deserializer,
NULL,
NULL);
formats = gdk_pixbuf_get_formats ();
/* Make sure png comes first */
for (f = formats; f; f = f->next)
{
GdkPixbufFormat *fmt = f->data;
char *name;
char *name;
name = gdk_pixbuf_format_get_name (fmt);
if (g_str_equal (name, "png"))
{
formats = g_slist_delete_link (formats, f);
formats = g_slist_prepend (formats, fmt);
{
formats = g_slist_delete_link (formats, f);
formats = g_slist_prepend (formats, fmt);
g_free (name);
break;
}
g_free (name);
break;
}
g_free (name);
}
}
for (f = formats; f; f = f->next)
{
GdkPixbufFormat *fmt = f->data;
char **mimes, **m;
char *name;
name = gdk_pixbuf_format_get_name (fmt);
mimes = gdk_pixbuf_format_get_mime_types (fmt);
for (m = mimes; *m; m++)
{
gdk_content_register_deserializer (*m,
GDK_TYPE_TEXTURE,
pixbuf_deserializer,
NULL,
NULL);
{
/* Turning pngs, jpegs and tiffs into textures is handled above */
if (!g_str_equal (name, "png") &&
!g_str_equal (name, "jpeg") &&
!g_str_equal (name, "tiff"))
gdk_content_register_deserializer (*m,
GDK_TYPE_TEXTURE,
pixbuf_deserializer,
NULL,
NULL);
gdk_content_register_deserializer (*m,
GDK_TYPE_PIXBUF,
pixbuf_deserializer,
NULL,
NULL);
}
}
g_strfreev (mimes);
g_free (name);
}
g_slist_free (formats);

View File

@@ -179,6 +179,76 @@ gdk_content_formats_new_for_gtype (GType type)
return gdk_content_formats_new_take (data, 1, NULL, 0);
}
/**
* gdk_content_formats_parse:
* @string: the string to parse
*
* Parses the given @string into `GdkContentFormats` and
* returns the formats.
*
* Strings printed via [method@Gdk.ContentFormats.to_string]
* can be read in again successfully using this function.
*
* If @string does not describe valid content formats, %NULL
* is returned.
*
* Returns: (nullable): the content formats if @string is valid
*
* Since: 4.4
*/
GdkContentFormats *
gdk_content_formats_parse (const char *string)
{
GdkContentFormatsBuilder *builder;
char **split;
gsize i;
g_return_val_if_fail (string != NULL, NULL);
split = g_strsplit_set (string, "\t\n\f\r ", -1); /* same as g_ascii_isspace() */
builder = gdk_content_formats_builder_new ();
/* first the GTypes */
for (i = 0; split[i] != NULL; i++)
{
GType type;
if (split[i][0] == 0)
continue;
type = g_type_from_name (split[i]);
if (type != 0)
gdk_content_formats_builder_add_gtype (builder, type);
else
break;
}
/* then the mime types */
for (; split[i] != NULL; i++)
{
const char *mime_type;
if (split[i][0] == 0)
continue;
mime_type = gdk_intern_mime_type (split[i]);
if (mime_type)
gdk_content_formats_builder_add_mime_type (builder, mime_type);
else
break;
}
if (split[i] != NULL)
{
g_strfreev (split);
gdk_content_formats_builder_unref (builder);
return NULL;
}
g_strfreev (split);
return gdk_content_formats_builder_free_to_formats (builder);
}
/**
* gdk_content_formats_ref:
* @formats: a `GdkContentFormats`
@@ -227,10 +297,8 @@ gdk_content_formats_unref (GdkContentFormats *formats)
*
* Prints the given @formats into a string for human consumption.
*
* This is meant for debugging and logging.
*
* The form of the representation may change at any time and is
* not guaranteed to stay identical.
* The result of this function can later be parsed with
* [func@Gdk.ContentFormats.parse].
*/
void
gdk_content_formats_print (GdkContentFormats *formats,
@@ -241,20 +309,18 @@ gdk_content_formats_print (GdkContentFormats *formats,
g_return_if_fail (formats != NULL);
g_return_if_fail (string != NULL);
g_string_append (string, "{ ");
for (i = 0; i < formats->n_gtypes; i++)
{
if (i > 0)
g_string_append (string, ", ");
g_string_append (string, " ");
g_string_append (string, g_type_name (formats->gtypes[i]));
}
for (i = 0; i < formats->n_mime_types; i++)
{
if (i > 0 || formats->n_gtypes > 0)
g_string_append (string, ", ");
g_string_append (string, " ");
g_string_append (string, formats->mime_types[i]);
}
g_string_append (string, " }");
}
/**
@@ -263,6 +329,8 @@ gdk_content_formats_print (GdkContentFormats *formats,
*
* Prints the given @formats into a human-readable string.
*
* The resulting string can be parsed with [func@Gdk.ContentFormats.parse].
*
* This is a small wrapper around [method@Gdk.ContentFormats.print]
* to help when debugging.
*

View File

@@ -40,6 +40,8 @@ GdkContentFormats * gdk_content_formats_new (const char
guint n_mime_types);
GDK_AVAILABLE_IN_ALL
GdkContentFormats * gdk_content_formats_new_for_gtype (GType type);
GDK_AVAILABLE_IN_4_4
GdkContentFormats * gdk_content_formats_parse (const char *string);
GDK_AVAILABLE_IN_ALL
GdkContentFormats * gdk_content_formats_ref (GdkContentFormats *formats);
GDK_AVAILABLE_IN_ALL

View File

@@ -80,7 +80,7 @@ gdk_content_provider_value_get_value (GdkContentProvider *provider,
{
GdkContentProviderValue *content = GDK_CONTENT_PROVIDER_VALUE (provider);
if (G_VALUE_HOLDS (value, G_VALUE_TYPE (&content->value)))
if (G_VALUE_HOLDS (&content->value, G_VALUE_TYPE (value)))
{
g_value_copy (&content->value, value);
return TRUE;

View File

@@ -26,6 +26,10 @@
#include "filetransferportalprivate.h"
#include "gdktextureprivate.h"
#include "gdkrgba.h"
#include "loaders/gdkpngprivate.h"
#include "loaders/gdktiffprivate.h"
#include "loaders/gdkjpegprivate.h"
#include "gdkmemorytextureprivate.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <string.h>
@@ -606,6 +610,7 @@ gdk_content_serialize_finish (GAsyncResult *result,
/*** SERIALIZERS ***/
static void
pixbuf_serializer_finish (GObject *source,
GAsyncResult *res,
@@ -658,6 +663,77 @@ pixbuf_serializer (GdkContentSerializer *serializer)
g_object_unref (pixbuf);
}
static void
texture_serializer_finish (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
GdkContentSerializer *serializer = GDK_CONTENT_SERIALIZER (source);
GError *error = NULL;
if (!g_task_propagate_boolean (G_TASK (res), &error))
gdk_content_serializer_return_error (serializer, error);
else
gdk_content_serializer_return_success (serializer);
}
static void
serialize_texture_in_thread (GTask *task,
gpointer source_object,
gpointer task_data,
GCancellable *cancellable)
{
GdkContentSerializer *serializer = source_object;
const GValue *value;
GdkTexture *texture;
GBytes *bytes = NULL;
GError *error = NULL;
gboolean result = FALSE;
GInputStream *input;
gssize spliced;
value = gdk_content_serializer_get_value (serializer);
texture = g_value_get_object (value);
if (strcmp (gdk_content_serializer_get_mime_type (serializer), "image/png") == 0)
bytes = gdk_save_png (texture);
else if (strcmp (gdk_content_serializer_get_mime_type (serializer), "image/tiff") == 0)
bytes = gdk_save_tiff (texture);
else if (strcmp (gdk_content_serializer_get_mime_type (serializer), "image/jpeg") == 0)
bytes = gdk_save_jpeg (texture);
else
g_assert_not_reached ();
input = g_memory_input_stream_new_from_bytes (bytes);
spliced = g_output_stream_splice (gdk_content_serializer_get_output_stream (serializer),
input,
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE,
gdk_content_serializer_get_cancellable (serializer),
&error);
g_object_unref (input);
g_bytes_unref (bytes);
result = spliced != -1;
if (result)
g_task_return_boolean (task, result);
else
g_task_return_error (task, error);
}
static void
texture_serializer (GdkContentSerializer *serializer)
{
GTask *task;
task = g_task_new (serializer,
gdk_content_serializer_get_cancellable (serializer),
texture_serializer_finish,
NULL);
g_task_run_in_thread (task, serialize_texture_in_thread);
g_object_unref (task);
}
static void
string_serializer_finish (GObject *source,
GAsyncResult *result,
@@ -877,51 +953,72 @@ init (void)
initialized = TRUE;
gdk_content_register_serializer (GDK_TYPE_TEXTURE,
"image/png",
texture_serializer,
NULL, NULL);
gdk_content_register_serializer (GDK_TYPE_TEXTURE,
"image/tiff",
texture_serializer,
NULL, NULL);
gdk_content_register_serializer (GDK_TYPE_TEXTURE,
"image/jpeg",
texture_serializer,
NULL, NULL);
formats = gdk_pixbuf_get_formats ();
/* Make sure png comes first */
for (f = formats; f; f = f->next)
{
GdkPixbufFormat *fmt = f->data;
char *name;
char *name;
name = gdk_pixbuf_format_get_name (fmt);
if (g_str_equal (name, "png"))
{
formats = g_slist_delete_link (formats, f);
formats = g_slist_prepend (formats, fmt);
{
formats = g_slist_delete_link (formats, f);
formats = g_slist_prepend (formats, fmt);
g_free (name);
break;
}
g_free (name);
break;
}
g_free (name);
}
}
for (f = formats; f; f = f->next)
{
GdkPixbufFormat *fmt = f->data;
char **mimes, **m;
char *name;
if (!gdk_pixbuf_format_is_writable (fmt))
continue;
continue;
name = gdk_pixbuf_format_get_name (fmt);
mimes = gdk_pixbuf_format_get_mime_types (fmt);
for (m = mimes; *m; m++)
{
gdk_content_register_serializer (GDK_TYPE_TEXTURE,
*m,
pixbuf_serializer,
gdk_pixbuf_format_get_name (fmt),
g_free);
{
/* Turning textures into pngs, tiffs or jpegs is handled above */
if (!g_str_equal (name, "png") &&
!g_str_equal (name, "tiff") &&
!g_str_equal (name, "jpeg"))
gdk_content_register_serializer (GDK_TYPE_TEXTURE,
*m,
pixbuf_serializer,
gdk_pixbuf_format_get_name (fmt),
g_free);
gdk_content_register_serializer (GDK_TYPE_PIXBUF,
*m,
pixbuf_serializer,
gdk_pixbuf_format_get_name (fmt),
g_free);
}
}
g_strfreev (mimes);
g_free (name);
}
g_slist_free (formats);

View File

@@ -41,10 +41,12 @@ typedef enum {
GDK_DEBUG_GL_LEGACY = 1 << 15,
GDK_DEBUG_GL_GLES = 1 << 16,
GDK_DEBUG_GL_DEBUG = 1 << 17,
GDK_DEBUG_GL_GLX = 1 << 18,
GDK_DEBUG_VULKAN_DISABLE = 1 << 19,
GDK_DEBUG_VULKAN_VALIDATE = 1 << 20,
GDK_DEBUG_DEFAULT_SETTINGS= 1 << 21
GDK_DEBUG_GL_EGL = 1 << 18,
GDK_DEBUG_GL_GLX = 1 << 19,
GDK_DEBUG_GL_WGL = 1 << 20,
GDK_DEBUG_VULKAN_DISABLE = 1 << 21,
GDK_DEBUG_VULKAN_VALIDATE = 1 << 22,
GDK_DEBUG_DEFAULT_SETTINGS= 1 << 23,
} GdkDebugFlags;
extern guint _gdk_debug_flags;

View File

@@ -77,6 +77,23 @@ enum {
LAST_SIGNAL
};
typedef struct _GdkDisplayPrivate GdkDisplayPrivate;
struct _GdkDisplayPrivate {
/* The base context that all other contexts inherit from.
* This context is never exposed to public API and is
* allowed to have a %NULL surface.
*/
GdkGLContext *gl_context;
GError *gl_error;
guint rgba : 1;
guint composited : 1;
guint input_shapes : 1;
GdkDebugFlags debug_flags;
};
static void gdk_display_dispose (GObject *object);
static void gdk_display_finalize (GObject *object);
@@ -85,7 +102,7 @@ static GdkAppLaunchContext *gdk_display_real_get_app_launch_context (GdkDisplay
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (GdkDisplay, gdk_display, G_TYPE_OBJECT)
G_DEFINE_TYPE_WITH_PRIVATE (GdkDisplay, gdk_display, G_TYPE_OBJECT)
static void
gdk_display_get_property (GObject *object,
@@ -119,10 +136,14 @@ gdk_display_real_make_default (GdkDisplay *display)
{
}
static void
gdk_display_real_opened (GdkDisplay *display)
static GdkGLContext *
gdk_display_default_init_gl (GdkDisplay *display,
GError **error)
{
_gdk_display_manager_add_display (gdk_display_manager_get (), display);
g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
_("The current backend does not support OpenGL"));
return NULL;
}
static GdkSeat *
@@ -134,6 +155,12 @@ gdk_display_real_get_default_seat (GdkDisplay *display)
return display->seats->data;
}
static void
gdk_display_real_opened (GdkDisplay *display)
{
_gdk_display_manager_add_display (gdk_display_manager_get (), display);
}
static void
gdk_display_class_init (GdkDisplayClass *class)
{
@@ -143,10 +170,11 @@ gdk_display_class_init (GdkDisplayClass *class)
object_class->dispose = gdk_display_dispose;
object_class->get_property = gdk_display_get_property;
class->get_app_launch_context = gdk_display_real_get_app_launch_context;
class->opened = gdk_display_real_opened;
class->make_default = gdk_display_real_make_default;
class->get_app_launch_context = gdk_display_real_get_app_launch_context;
class->init_gl = gdk_display_default_init_gl;
class->get_default_seat = gdk_display_real_get_default_seat;
class->opened = gdk_display_real_opened;
/**
* GdkDisplay:composited: (attributes org.gtk.Property.get=gdk_display_is_composited)
@@ -294,6 +322,8 @@ free_device_grabs_foreach (gpointer key,
static void
gdk_display_init (GdkDisplay *display)
{
GdkDisplayPrivate *priv = gdk_display_get_instance_private (display);
display->double_click_time = 250;
display->double_click_distance = 5;
@@ -304,22 +334,26 @@ gdk_display_init (GdkDisplay *display)
g_queue_init (&display->queued_events);
display->debug_flags = _gdk_debug_flags;
priv->debug_flags = _gdk_debug_flags;
display->composited = TRUE;
display->rgba = TRUE;
display->input_shapes = TRUE;
priv->composited = TRUE;
priv->rgba = TRUE;
priv->input_shapes = TRUE;
}
static void
gdk_display_dispose (GObject *object)
{
GdkDisplay *display = GDK_DISPLAY (object);
GdkDisplayPrivate *priv = gdk_display_get_instance_private (display);
_gdk_display_manager_remove_display (gdk_display_manager_get (), display);
g_queue_clear (&display->queued_events);
g_clear_object (&priv->gl_context);
g_clear_error (&priv->gl_error);
G_OBJECT_CLASS (gdk_display_parent_class)->dispose (object);
}
@@ -998,21 +1032,25 @@ gdk_display_get_primary_clipboard (GdkDisplay *display)
gboolean
gdk_display_supports_input_shapes (GdkDisplay *display)
{
GdkDisplayPrivate *priv = gdk_display_get_instance_private (display);
g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
return display->input_shapes;
return priv->input_shapes;
}
void
gdk_display_set_input_shapes (GdkDisplay *display,
gboolean input_shapes)
{
GdkDisplayPrivate *priv = gdk_display_get_instance_private (display);
g_return_if_fail (GDK_IS_DISPLAY (display));
if (display->input_shapes == input_shapes)
if (priv->input_shapes == input_shapes)
return;
display->input_shapes = input_shapes;
priv->input_shapes = input_shapes;
g_object_notify_by_pspec (G_OBJECT (display), props[PROP_INPUT_SHAPES]);
}
@@ -1157,32 +1195,136 @@ gdk_display_get_keymap (GdkDisplay *display)
return GDK_DISPLAY_GET_CLASS (display)->get_keymap (display);
}
/*< private >
* gdk_display_make_gl_context_current:
* @display: a `GdkDisplay`
* @context: (optional): a `GdkGLContext`
*
* Makes the given @context the current GL context, or unsets
* the current GL context if @context is %NULL.
*/
gboolean
gdk_display_make_gl_context_current (GdkDisplay *display,
GdkGLContext *context)
static void
gdk_display_init_gl (GdkDisplay *self)
{
return GDK_DISPLAY_GET_CLASS (display)->make_gl_context_current (display, context);
GdkDisplayPrivate *priv = gdk_display_get_instance_private (self);
GdkGLContext *context;
gint64 before G_GNUC_UNUSED;
gint64 before2 G_GNUC_UNUSED;
before = GDK_PROFILER_CURRENT_TIME;
if (GDK_DISPLAY_DEBUG_CHECK (self, GL_DISABLE))
{
g_set_error_literal (&priv->gl_error, GDK_GL_ERROR,
GDK_GL_ERROR_NOT_AVAILABLE,
_("GL support disabled via GDK_DEBUG"));
return;
}
context = GDK_DISPLAY_GET_CLASS (self)->init_gl (self, &priv->gl_error);
if (context == NULL)
return;
before2 = GDK_PROFILER_CURRENT_TIME;
if (!gdk_gl_context_realize (context, &priv->gl_error))
{
g_object_unref (context);
return;
}
gdk_profiler_end_mark (before2, "realize OpenGL context", NULL);
/* Only assign after realize, so GdkGLContext::realize() can use
* gdk_display_get_gl_context() == NULL to differentiate between
* the display's context and any other context.
*/
priv->gl_context = context;
gdk_profiler_end_mark (before, "initialize OpenGL", NULL);
}
/**
* gdk_display_prepare_gl:
* @self: a `GdkDisplay`
* @error: return location for a `GError`
*
* Checks that OpenGL is available for @self and ensures that it is
* properly initialized.
* When this fails, an @error will be set describing the error and this
* function returns %FALSE.
*
* Note that even if this function succeeds, creating a `GdkGLContext`
* may still fail.
*
* This function is idempotent. Calling it multiple times will just
* return the same value or error.
*
* You never need to call this function, GDK will call it automatically
* as needed. But you can use it as a check when setting up code that
* might make use of OpenGL.
*
* Returns: %TRUE if the display supports OpenGL
*
* Since: 4.4
**/
gboolean
gdk_display_prepare_gl (GdkDisplay *self,
GError **error)
{
GdkDisplayPrivate *priv = gdk_display_get_instance_private (self);
g_return_val_if_fail (GDK_IS_DISPLAY (self), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
for (;;)
{
if (priv->gl_context)
return TRUE;
if (priv->gl_error != NULL)
{
if (error)
*error = g_error_copy (priv->gl_error);
return FALSE;
}
gdk_display_init_gl (self);
/* try again */
}
}
/*< private >
* gdk_display_get_gl_context:
* @self: the `GdkDisplay`
*
* Gets the GL context returned from [vfunc@Gdk.Display.init_gl]
* previously.
*
* If that function has not been called yet or did fail, %NULL is
* returned.
* Call [method@Gdk.Display.prepare_gl] to avoid this.
*
* Returns: The `GdkGLContext`
*/
GdkGLContext *
gdk_display_get_gl_context (GdkDisplay *self)
{
GdkDisplayPrivate *priv = gdk_display_get_instance_private (self);
return priv->gl_context;
}
GdkDebugFlags
gdk_display_get_debug_flags (GdkDisplay *display)
{
return display ? display->debug_flags : _gdk_debug_flags;
GdkDisplayPrivate *priv = gdk_display_get_instance_private (display);
return display ? priv->debug_flags : _gdk_debug_flags;
}
void
gdk_display_set_debug_flags (GdkDisplay *display,
GdkDebugFlags flags)
{
display->debug_flags = flags;
GdkDisplayPrivate *priv = gdk_display_get_instance_private (display);
priv->debug_flags = flags;
}
/**
@@ -1207,21 +1349,25 @@ gdk_display_set_debug_flags (GdkDisplay *display,
gboolean
gdk_display_is_composited (GdkDisplay *display)
{
GdkDisplayPrivate *priv = gdk_display_get_instance_private (display);
g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
return display->composited;
return priv->composited;
}
void
gdk_display_set_composited (GdkDisplay *display,
gboolean composited)
{
GdkDisplayPrivate *priv = gdk_display_get_instance_private (display);
g_return_if_fail (GDK_IS_DISPLAY (display));
if (display->composited == composited)
if (priv->composited == composited)
return;
display->composited = composited;
priv->composited = composited;
g_object_notify_by_pspec (G_OBJECT (display), props[PROP_COMPOSITED]);
}
@@ -1248,21 +1394,25 @@ gdk_display_set_composited (GdkDisplay *display,
gboolean
gdk_display_is_rgba (GdkDisplay *display)
{
GdkDisplayPrivate *priv = gdk_display_get_instance_private (display);
g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
return display->rgba;
return priv->rgba;
}
void
gdk_display_set_rgba (GdkDisplay *display,
gboolean rgba)
{
GdkDisplayPrivate *priv = gdk_display_get_instance_private (display);
g_return_if_fail (GDK_IS_DISPLAY (display));
if (display->rgba == rgba)
if (priv->rgba == rgba)
return;
display->rgba = rgba;
priv->rgba = rgba;
g_object_notify_by_pspec (G_OBJECT (display), props[PROP_RGBA]);
}

View File

@@ -68,6 +68,10 @@ gboolean gdk_display_is_rgba (GdkDisplay *display);
GDK_AVAILABLE_IN_ALL
gboolean gdk_display_supports_input_shapes (GdkDisplay *display);
GDK_AVAILABLE_IN_4_4
gboolean gdk_display_prepare_gl (GdkDisplay *self,
GError **error);
GDK_AVAILABLE_IN_ALL
GdkDisplay *gdk_display_get_default (void);

View File

@@ -102,11 +102,6 @@ struct _GdkDisplay
guint vulkan_refcount;
#endif /* GDK_RENDERING_VULKAN */
guint rgba : 1;
guint composited : 1;
guint input_shapes : 1;
GdkDebugFlags debug_flags;
GList *seats;
};
@@ -145,8 +140,8 @@ struct _GdkDisplayClass
GdkKeymap * (*get_keymap) (GdkDisplay *display);
gboolean (*make_gl_context_current) (GdkDisplay *display,
GdkGLContext *context);
GdkGLContext * (*init_gl) (GdkDisplay *display,
GError **error);
GdkSeat * (*get_default_seat) (GdkDisplay *display);
@@ -211,8 +206,7 @@ GdkSurface * gdk_display_create_surface (GdkDisplay *display
int width,
int height);
gboolean gdk_display_make_gl_context_current (GdkDisplay *display,
GdkGLContext *context);
GdkGLContext * gdk_display_get_gl_context (GdkDisplay *display);
void gdk_display_set_rgba (GdkDisplay *display,
gboolean rgba);

View File

@@ -69,7 +69,7 @@ GDK_AVAILABLE_IN_ALL
GdkDragAction gdk_drag_get_selected_action (GdkDrag *drag);
GDK_AVAILABLE_IN_ALL
gboolean gdk_drag_action_is_unique (GdkDragAction action);
gboolean gdk_drag_action_is_unique (GdkDragAction action) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GdkDrag * gdk_drag_begin (GdkSurface *surface,

View File

@@ -43,6 +43,7 @@
typedef struct _GdkDrawContextPrivate GdkDrawContextPrivate;
struct _GdkDrawContextPrivate {
GdkDisplay *display;
GdkSurface *surface;
cairo_region_t *frame_region;
@@ -77,6 +78,7 @@ gdk_draw_context_dispose (GObject *gobject)
priv->surface->draw_contexts = g_slist_remove (priv->surface->draw_contexts, context);
g_clear_object (&priv->surface);
}
g_clear_object (&priv->display);
G_OBJECT_CLASS (gdk_draw_context_parent_class)->dispose (gobject);
}
@@ -92,10 +94,31 @@ gdk_draw_context_set_property (GObject *gobject,
switch (prop_id)
{
case PROP_DISPLAY:
if (priv->display != NULL)
{
g_assert (g_value_get_object (value) == NULL);
}
else
{
priv->display = g_value_dup_object (value);
}
break;
case PROP_SURFACE:
priv->surface = g_value_dup_object (value);
g_assert (priv->surface != NULL);
priv->surface->draw_contexts = g_slist_prepend (priv->surface->draw_contexts, context);
if (priv->surface)
{
priv->surface->draw_contexts = g_slist_prepend (priv->surface->draw_contexts, context);
if (priv->display)
{
g_assert (priv->display == gdk_surface_get_display (priv->surface));
}
else
{
priv->display = g_object_ref (gdk_surface_get_display (priv->surface));
}
}
break;
default:
@@ -148,7 +171,8 @@ gdk_draw_context_class_init (GdkDrawContextClass *klass)
P_("Display"),
P_("The GDK display used to create the context"),
GDK_TYPE_DISPLAY,
G_PARAM_READABLE |
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
/**
@@ -228,7 +252,7 @@ gdk_draw_context_get_display (GdkDrawContext *context)
g_return_val_if_fail (GDK_IS_DRAW_CONTEXT (context), NULL);
return priv->surface ? gdk_surface_get_display (priv->surface) : NULL;
return priv->display;
}
/**

View File

@@ -29,6 +29,7 @@
#include "gdkinternals.h"
#include "gdkframeclockprivate.h"
#include "gdk.h"
#include "gdk-private.h"
#include "gdkprofilerprivate.h"
#ifdef G_OS_WIN32
@@ -307,12 +308,15 @@ maybe_start_idle (GdkFrameClockIdle *clock_idle,
if (priv->flush_idle_id == 0 && RUN_FLUSH_IDLE (priv))
{
GSource *source;
priv->flush_idle_id = g_timeout_add_full (GDK_PRIORITY_EVENTS + 1,
min_interval,
gdk_frame_clock_flush_idle,
g_object_ref (clock_idle),
(GDestroyNotify) g_object_unref);
g_source_set_name_by_id (priv->flush_idle_id, "[gtk] gdk_frame_clock_flush_idle");
source = g_main_context_find_source_by_id (NULL, priv->flush_idle_id);
g_source_set_static_name (source, "[gtk] gdk_frame_clock_flush_idle");
}
if (!priv->in_paint_idle &&
@@ -324,7 +328,7 @@ maybe_start_idle (GdkFrameClockIdle *clock_idle,
gdk_frame_clock_paint_idle,
g_object_ref (clock_idle),
(GDestroyNotify) g_object_unref);
g_source_set_name_by_id (priv->paint_idle_id, "[gtk] gdk_frame_clock_paint_idle");
gdk_source_set_static_name_by_id (priv->paint_idle_id, "[gtk] gdk_frame_clock_paint_idle");
}
}
}

View File

@@ -301,7 +301,7 @@ gdk_gl_texture_quads (GdkGLContext *paint_context,
* @width: The width of the region to draw
* @height: The height of the region to draw
*
* The main way to draw GL content in GTK.
* The main way to not draw GL content in GTK.
*
* It takes a render buffer ID (@source_type == GL_RENDERBUFFER) or a texture
* id (@source_type == GL_TEXTURE) and draws it onto @cr with an OVER operation,
@@ -319,6 +319,12 @@ gdk_gl_texture_quads (GdkGLContext *paint_context,
* with alpha components, so make sure you use GL_TEXTURE if using alpha.
*
* Calling this may change the current GL context.
*
* Deprecated: 4.6: The function is overly complex and produces broken output
* in various combinations of arguments. If you want to draw with GL textures
* in GTK, use [ctor@Gdk.GLTexture.new]; if you want to use that texture in
* Cairo, use [method@Gdk.Texture.download] to download the data into a Cairo
* image surface.
*/
void
gdk_cairo_draw_from_gl (cairo_t *cr,

View File

@@ -89,8 +89,6 @@
#include <epoxy/gl.h>
typedef struct {
GdkGLContext *shared_context;
int major;
int minor;
int gl_version;
@@ -127,7 +125,28 @@ G_DEFINE_QUARK (gdk-gl-error-quark, gdk_gl_error)
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GdkGLContext, gdk_gl_context, GDK_TYPE_DRAW_CONTEXT)
static GPrivate thread_current_context = G_PRIVATE_INIT (g_object_unref);
typedef struct _MaskedContext MaskedContext;
static inline MaskedContext *
mask_context (GdkGLContext *context,
gboolean surfaceless)
{
return (MaskedContext *) GSIZE_TO_POINTER (GPOINTER_TO_SIZE (context) | (surfaceless ? 1 : 0));
}
static inline GdkGLContext *
unmask_context (MaskedContext *mask)
{
return GDK_GL_CONTEXT (GSIZE_TO_POINTER (GPOINTER_TO_SIZE (mask) & ~(gsize) 1));
}
static void
unref_unmasked (gpointer data)
{
g_object_unref (unmask_context (data));
}
static GPrivate thread_current_context = G_PRIVATE_INIT (unref_unmasked);
static void
gdk_gl_context_clear_old_updated_area (GdkGLContext *context)
@@ -144,17 +163,14 @@ static void
gdk_gl_context_dispose (GObject *gobject)
{
GdkGLContext *context = GDK_GL_CONTEXT (gobject);
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
GdkGLContext *current;
MaskedContext *current;
gdk_gl_context_clear_old_updated_area (context);
current = g_private_get (&thread_current_context);
if (current == context)
if (unmask_context (current) == context)
g_private_replace (&thread_current_context, NULL);
g_clear_object (&priv->shared_context);
G_OBJECT_CLASS (gdk_gl_context_parent_class)->dispose (gobject);
}
@@ -174,17 +190,10 @@ gdk_gl_context_set_property (GObject *gobject,
const GValue *value,
GParamSpec *pspec)
{
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private ((GdkGLContext *) gobject);
switch (prop_id)
{
case PROP_SHARED_CONTEXT:
{
GdkGLContext *context = g_value_get_object (value);
if (context != NULL)
priv->shared_context = g_object_ref (context);
}
g_assert (g_value_get_object (value) == NULL);
break;
default:
@@ -198,12 +207,10 @@ gdk_gl_context_get_property (GObject *gobject,
GValue *value,
GParamSpec *pspec)
{
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private ((GdkGLContext *) gobject);
switch (prop_id)
{
case PROP_SHARED_CONTEXT:
g_value_set_object (value, priv->shared_context);
g_value_set_object (value, NULL);
break;
default:
@@ -222,64 +229,83 @@ gdk_gl_context_upload_texture (GdkGLContext *context,
{
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
guchar *copy = NULL;
guint gl_format;
guint gl_type;
guint bpp;
GLint gl_internalformat;
GLint gl_format;
GLint gl_type;
gsize bpp;
g_return_if_fail (GDK_IS_GL_CONTEXT (context));
if (priv->use_es)
if (!priv->use_es && data_format == GDK_MEMORY_DEFAULT) /* Cairo surface format */
{
/* GLES only supports rgba, so convert if necessary */
if (data_format != GDK_MEMORY_R8G8B8A8_PREMULTIPLIED)
{
copy = g_malloc (width * height * 4);
gdk_memory_convert (copy, width * 4,
GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
data, stride, data_format,
width, height);
stride = width * 4;
data = copy;
}
bpp = 4;
gl_internalformat = GL_RGBA8;
gl_format = GL_BGRA;
gl_type = GL_UNSIGNED_INT_8_8_8_8_REV;
}
else if (data_format == GDK_MEMORY_R8G8B8) /* Pixmap non-alpha data */
{
gl_internalformat = GL_RGBA8;
gl_format = GL_RGB;
gl_type = GL_UNSIGNED_BYTE;
}
else if (priv->use_es && data_format == GDK_MEMORY_B8G8R8)
{
gl_internalformat = GL_RGBA8;
gl_format = GL_BGR;
gl_type = GL_UNSIGNED_BYTE;
}
else if (data_format == GDK_MEMORY_R16G16B16)
{
gl_internalformat = GL_RGBA16;
gl_format = GL_RGB;
gl_type = GL_UNSIGNED_SHORT;
}
else if (data_format == GDK_MEMORY_R16G16B16A16_PREMULTIPLIED)
{
gl_internalformat = GL_RGBA16;
gl_format = GL_RGBA;
gl_type = GL_UNSIGNED_SHORT;
}
else if (data_format == GDK_MEMORY_R16G16B16_FLOAT)
{
gl_internalformat = GL_RGB16F;
gl_format = GL_RGB;
gl_type = GL_HALF_FLOAT;
}
else if (data_format == GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED)
{
gl_internalformat = GL_RGBA16F;
gl_format = GL_RGBA;
gl_type = GL_HALF_FLOAT;
}
else if (data_format == GDK_MEMORY_R32G32B32_FLOAT)
{
gl_internalformat = GL_RGB32F;
gl_format = GL_RGB;
gl_type = GL_FLOAT;
}
else if (data_format == GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED)
{
gl_internalformat = GL_RGBA32F;
gl_format = GL_RGBA;
gl_type = GL_FLOAT;
}
else /* Fall-back, convert to GLES format */
{
copy = g_malloc (width * height * 4);
gdk_memory_convert (copy, width * 4,
GDK_MEMORY_CONVERT_GLES_RGBA,
data, stride, data_format,
width, height);
data_format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
stride = width * 4;
data = copy;
gl_internalformat = GL_RGBA8;
gl_format = GL_RGBA;
gl_type = GL_UNSIGNED_BYTE;
}
else
{
if (data_format == GDK_MEMORY_DEFAULT) /* Cairo surface format */
{
gl_format = GL_BGRA;
gl_type = GL_UNSIGNED_INT_8_8_8_8_REV;
bpp = 4;
}
else if (data_format == GDK_MEMORY_R8G8B8) /* Pixmap non-alpha data */
{
gl_format = GL_RGB;
gl_type = GL_UNSIGNED_BYTE;
bpp = 3;
}
else if (data_format == GDK_MEMORY_B8G8R8)
{
gl_format = GL_BGR;
gl_type = GL_UNSIGNED_BYTE;
bpp = 3;
}
else /* Fall-back, convert to cairo-surface-format */
{
copy = g_malloc (width * height * 4);
gdk_memory_convert (copy, width * 4,
GDK_MEMORY_DEFAULT,
data, stride, data_format,
width, height);
stride = width * 4;
bpp = 4;
data = copy;
gl_format = GL_BGRA;
gl_type = GL_UNSIGNED_INT_8_8_8_8_REV;
}
}
bpp = gdk_memory_format_bytes_per_pixel (data_format);
/* GL_UNPACK_ROW_LENGTH is available on desktop GL, OpenGL ES >= 3.0, or if
* the GL_EXT_unpack_subimage extension for OpenGL ES 2.0 is available
@@ -288,7 +314,7 @@ gdk_gl_context_upload_texture (GdkGLContext *context,
{
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexImage2D (texture_target, 0, GL_RGBA, width, height, 0, gl_format, gl_type, data);
glTexImage2D (texture_target, 0, gl_internalformat, width, height, 0, gl_format, gl_type, data);
glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
}
else if ((!priv->use_es ||
@@ -296,14 +322,14 @@ gdk_gl_context_upload_texture (GdkGLContext *context,
{
glPixelStorei (GL_UNPACK_ROW_LENGTH, stride / bpp);
glTexImage2D (texture_target, 0, GL_RGBA, width, height, 0, gl_format, gl_type, data);
glTexImage2D (texture_target, 0, gl_internalformat, width, height, 0, gl_format, gl_type, data);
glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
}
else
{
int i;
glTexImage2D (texture_target, 0, GL_RGBA, width, height, 0, gl_format, gl_type, NULL);
glTexImage2D (texture_target, 0, gl_internalformat, width, height, 0, gl_format, gl_type, NULL);
for (i = 0; i < height; i++)
glTexSubImage2D (texture_target, 0, 0, i, width, 1, gl_format, gl_type, data + (i * stride));
}
@@ -333,23 +359,27 @@ gdk_gl_context_real_get_damage (GdkGLContext *context)
});
}
static gboolean
gdk_gl_context_real_is_shared (GdkGLContext *self,
GdkGLContext *other)
{
if (gdk_draw_context_get_display (GDK_DRAW_CONTEXT (self)) != gdk_draw_context_get_display (GDK_DRAW_CONTEXT (other)))
return FALSE;
/* XXX: Should we check es or legacy here? */
return TRUE;
}
static void
gdk_gl_context_real_begin_frame (GdkDrawContext *draw_context,
cairo_region_t *region)
{
GdkGLContext *context = GDK_GL_CONTEXT (draw_context);
GdkSurface *surface;
GdkGLContext *shared;
cairo_region_t *damage;
int ww, wh;
shared = gdk_gl_context_get_shared_context (context);
if (shared)
{
GDK_DRAW_CONTEXT_GET_CLASS (GDK_DRAW_CONTEXT (shared))->begin_frame (GDK_DRAW_CONTEXT (shared), region);
return;
}
damage = GDK_GL_CONTEXT_GET_CLASS (context)->get_damage (context);
if (context->old_updated_area[1])
@@ -379,15 +409,6 @@ static void
gdk_gl_context_real_end_frame (GdkDrawContext *draw_context,
cairo_region_t *painted)
{
GdkGLContext *context = GDK_GL_CONTEXT (draw_context);
GdkGLContext *shared;
shared = gdk_gl_context_get_shared_context (context);
if (shared)
{
GDK_DRAW_CONTEXT_GET_CLASS (GDK_DRAW_CONTEXT (shared))->end_frame (GDK_DRAW_CONTEXT (shared), painted);
return;
}
}
static void
@@ -406,6 +427,7 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
klass->realize = gdk_gl_context_real_realize;
klass->get_damage = gdk_gl_context_real_get_damage;
klass->is_shared = gdk_gl_context_real_is_shared;
draw_context_class->begin_frame = gdk_gl_context_real_begin_frame;
draw_context_class->end_frame = gdk_gl_context_real_end_frame;
@@ -414,7 +436,13 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
/**
* GdkGLContext:shared-context: (attributes org.gtk.Property.get=gdk_gl_context_get_shared_context)
*
* The `GdkGLContext` that this context is sharing data with, or %NULL
* Always %NULL
*
* As many contexts can share data now and no single shared context exists
* anymore, this function has been deprecated and now always returns %NULL.
*
* Deprecated: 4.4: Use [method@Gdk.GLContext.is_shared] to check if contexts
* can be shared.
*/
obj_pspecs[PROP_SHARED_CONTEXT] =
g_param_spec_object ("shared-context",
@@ -423,7 +451,8 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
GDK_TYPE_GL_CONTEXT,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
G_PARAM_STATIC_STRINGS |
G_PARAM_DEPRECATED);
gobject_class->set_property = gdk_gl_context_set_property;
gobject_class->get_property = gdk_gl_context_get_property;
@@ -441,6 +470,21 @@ gdk_gl_context_init (GdkGLContext *self)
priv->use_es = -1;
}
/* Must have called gdk_display_prepare_gl() before */
GdkGLContext *
gdk_gl_context_new_for_surface (GdkSurface *surface)
{
GdkDisplay *display = gdk_surface_get_display (surface);
GdkGLContext *shared = gdk_display_get_gl_context (display);
/* assert gdk_display_prepare_gl() had been called */
g_assert (shared);
return g_object_new (G_OBJECT_TYPE (shared),
"surface", surface,
NULL);
}
GdkGLContextPaintData *
gdk_gl_context_get_paint_data (GdkGLContext *context)
{
@@ -812,6 +856,44 @@ gdk_gl_context_set_is_legacy (GdkGLContext *context,
priv->is_legacy = !!is_legacy;
}
/**
* gdk_gl_context_is_shared:
* @self: a `GdkGLContext`
* @other: the `GdkGLContext` that should be compatible with @self
*
* Checks if the two GL contexts can share resources.
*
* When they can, the texture IDs from @other can be used in @self. This
* is particularly useful when passing `GdkGLTexture` objects between
* different contexts.
*
* Contexts created for the same display with the same properties will
* always be compatible, even if they are created for different surfaces.
* For other contexts it depends on the GL backend.
*
* Both contexts must be realized for this check to succeed. If either one
* is not, this function will return %FALSE.
*
* Returns: %TRUE if the two GL contexts are compatible.
*
* Since: 4.4
*/
gboolean
gdk_gl_context_is_shared (GdkGLContext *self,
GdkGLContext *other)
{
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
GdkGLContextPrivate *priv_other = gdk_gl_context_get_instance_private (other);
g_return_val_if_fail (GDK_IS_GL_CONTEXT (self), FALSE);
g_return_val_if_fail (GDK_IS_GL_CONTEXT (other), FALSE);
if (!priv->realized || !priv_other->realized)
return FALSE;
return GDK_GL_CONTEXT_GET_CLASS (self)->is_shared (self, other);
}
/**
* gdk_gl_context_set_use_es:
* @context: a `GdkGLContext`
@@ -1092,12 +1174,16 @@ void
gdk_gl_context_make_current (GdkGLContext *context)
{
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
GdkGLContext *current;
MaskedContext *current, *masked_context;
gboolean surfaceless;
g_return_if_fail (GDK_IS_GL_CONTEXT (context));
surfaceless = !gdk_draw_context_is_in_frame (GDK_DRAW_CONTEXT (context));
masked_context = mask_context (context, surfaceless);
current = g_private_get (&thread_current_context);
if (current == context)
if (current == masked_context)
return;
/* we need to realize the GdkGLContext if it wasn't explicitly realized */
@@ -1114,11 +1200,15 @@ gdk_gl_context_make_current (GdkGLContext *context)
}
}
if (gdk_display_make_gl_context_current (gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context)), context))
if (!GDK_GL_CONTEXT_GET_CLASS (context)->make_current (context, surfaceless))
{
g_private_replace (&thread_current_context, g_object_ref (context));
gdk_gl_context_check_extensions (context);
g_warning ("gdk_gl_context_make_current() failed");
return;
}
g_object_ref (context);
g_private_replace (&thread_current_context, masked_context);
gdk_gl_context_check_extensions (context);
}
/**
@@ -1157,18 +1247,22 @@ gdk_gl_context_get_surface (GdkGLContext *context)
* gdk_gl_context_get_shared_context: (attributes org.gtk.Method.get_property=shared-context)
* @context: a `GdkGLContext`
*
* Retrieves the `GdkGLContext` that this @context share data with.
* Used to retrieves the `GdkGLContext` that this @context share data with.
*
* Returns: (nullable) (transfer none): a `GdkGLContext`
* As many contexts can share data now and no single shared context exists
* anymore, this function has been deprecated and now always returns %NULL.
*
* Returns: (nullable) (transfer none): %NULL
*
* Deprecated: 4.4: Use [method@Gdk.GLContext.is_shared] to check if contexts
* can be shared.
*/
GdkGLContext *
gdk_gl_context_get_shared_context (GdkGLContext *context)
{
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), NULL);
return priv->shared_context;
return NULL;
}
/**
@@ -1208,12 +1302,14 @@ gdk_gl_context_get_version (GdkGLContext *context,
void
gdk_gl_context_clear_current (void)
{
GdkGLContext *current;
MaskedContext *current;
current = g_private_get (&thread_current_context);
if (current != NULL)
{
if (gdk_display_make_gl_context_current (gdk_draw_context_get_display (GDK_DRAW_CONTEXT (current)), NULL))
GdkGLContext *context = unmask_context (current);
if (GDK_GL_CONTEXT_GET_CLASS (context)->clear_current (context))
g_private_replace (&thread_current_context, NULL);
}
}
@@ -1228,11 +1324,11 @@ gdk_gl_context_clear_current (void)
GdkGLContext *
gdk_gl_context_get_current (void)
{
GdkGLContext *current;
MaskedContext *current;
current = g_private_get (&thread_current_context);
return current;
return unmask_context (current);
}
gboolean

View File

@@ -45,8 +45,8 @@ GType gdk_gl_context_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GdkDisplay * gdk_gl_context_get_display (GdkGLContext *context);
GDK_AVAILABLE_IN_ALL
GdkSurface * gdk_gl_context_get_surface (GdkGLContext *context);
GDK_AVAILABLE_IN_ALL
GdkSurface * gdk_gl_context_get_surface (GdkGLContext *context);
GDK_DEPRECATED_IN_4_4_FOR(gdk_gl_context_is_shared)
GdkGLContext * gdk_gl_context_get_shared_context (GdkGLContext *context);
GDK_AVAILABLE_IN_ALL
void gdk_gl_context_get_version (GdkGLContext *context,
@@ -54,6 +54,9 @@ void gdk_gl_context_get_version (GdkGLContext *
int *minor);
GDK_AVAILABLE_IN_ALL
gboolean gdk_gl_context_is_legacy (GdkGLContext *context);
GDK_AVAILABLE_IN_4_4
gboolean gdk_gl_context_is_shared (GdkGLContext *self,
GdkGLContext *other);
GDK_AVAILABLE_IN_ALL
void gdk_gl_context_set_required_version (GdkGLContext *context,

View File

@@ -27,6 +27,13 @@
G_BEGIN_DECLS
/* Version requirements for EGL contexts.
*
* If you add support for EGL to your backend, please require this.
*/
#define GDK_EGL_MIN_VERSION_MAJOR (1)
#define GDK_EGL_MIN_VERSION_MINOR (4)
#define GDK_GL_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_GL_CONTEXT, GdkGLContextClass))
#define GDK_IS_GL_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_GL_CONTEXT))
#define GDK_GL_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_GL_CONTEXT, GdkGLContextClass))
@@ -45,10 +52,16 @@ struct _GdkGLContextClass
{
GdkDrawContextClass parent_class;
gboolean (* realize) (GdkGLContext *context,
GError **error);
gboolean (* realize) (GdkGLContext *context,
GError **error);
cairo_region_t * (* get_damage) (GdkGLContext *context);
gboolean (* make_current) (GdkGLContext *context,
gboolean surfaceless);
gboolean (* clear_current) (GdkGLContext *context);
cairo_region_t * (* get_damage) (GdkGLContext *context);
gboolean (* is_shared) (GdkGLContext *self,
GdkGLContext *other);
};
typedef struct {
@@ -73,6 +86,8 @@ typedef struct {
guint use_es : 1;
} GdkGLContextPaintData;
GdkGLContext * gdk_gl_context_new_for_surface (GdkSurface *surface);
void gdk_gl_context_set_is_legacy (GdkGLContext *context,
gboolean is_legacy);

View File

@@ -20,7 +20,8 @@
#include "gdkgltextureprivate.h"
#include "gdkcairo.h"
#include "gdkdisplayprivate.h"
#include "gdkmemorytextureprivate.h"
#include "gdktextureprivate.h"
#include <epoxy/gl.h>
@@ -37,7 +38,7 @@ struct _GdkGLTexture {
GdkGLContext *context;
guint id;
cairo_surface_t *saved;
GdkTexture *saved;
GDestroyNotify destroy;
gpointer data;
@@ -64,50 +65,258 @@ gdk_gl_texture_dispose (GObject *object)
g_clear_object (&self->context);
self->id = 0;
if (self->saved)
{
cairo_surface_destroy (self->saved);
self->saved = NULL;
}
g_clear_object (&self->saved);
G_OBJECT_CLASS (gdk_gl_texture_parent_class)->dispose (object);
}
static void
gdk_gl_texture_download (GdkTexture *texture,
const GdkRectangle *area,
guchar *data,
gsize stride)
typedef struct _InvokeData
{
GdkGLTexture *self = GDK_GL_TEXTURE (texture);
cairo_surface_t *surface;
cairo_t *cr;
GdkGLTexture *self;
volatile int spinlock;
GFunc func;
gpointer data;
} InvokeData;
surface = cairo_image_surface_create_for_data (data,
CAIRO_FORMAT_ARGB32,
area->width, area->height,
stride);
static gboolean
gdk_gl_texture_invoke_callback (gpointer data)
{
InvokeData *invoke = data;
GdkGLContext *context;
cr = cairo_create (surface);
context = gdk_display_get_gl_context (gdk_gl_context_get_display (invoke->self->context));
if (self->saved)
gdk_gl_context_make_current (context);
glBindTexture (GL_TEXTURE_2D, invoke->self->id);
invoke->func (invoke->self, invoke->data);
g_atomic_int_set (&invoke->spinlock, 1);
return FALSE;
}
static void
gdk_gl_texture_run (GdkGLTexture *self,
GFunc func,
gpointer data)
{
InvokeData invoke = { self, 0, func, data };
g_main_context_invoke (NULL, gdk_gl_texture_invoke_callback, &invoke);
while (g_atomic_int_get (&invoke.spinlock) == 0);
}
static inline void
gdk_gl_texture_get_tex_image (GdkGLTexture *self,
GLenum gl_format,
GLenum gl_type,
GLvoid *data)
{
if (gdk_gl_context_get_use_es (self->context))
{
cairo_set_source_surface (cr, self->saved, 0, 0);
cairo_paint (cr);
GdkTexture *texture = GDK_TEXTURE (self);
GLuint fbo;
glGenFramebuffers (1, &fbo);
glBindFramebuffer (GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, self->id, 0);
glReadPixels (0, 0,
texture->width, texture->height,
gl_format,
gl_type,
data);
glBindFramebuffer (GL_FRAMEBUFFER, 0);
glDeleteFramebuffers (1, &fbo);
}
else
{
GdkSurface *gl_surface;
glGetTexImage (GL_TEXTURE_2D,
0,
gl_format,
gl_type,
data);
}
}
static void
gdk_gl_texture_do_download_texture (gpointer texture_,
gpointer result_)
{
GdkTexture *texture = texture_;
GdkTexture **result = result_;
GdkMemoryFormat format;
GLint internal_format, gl_format, gl_type;
guchar *data;
gsize stride;
GBytes *bytes;
gl_surface = gdk_gl_context_get_surface (self->context);
gdk_cairo_draw_from_gl (cr, gl_surface, self->id, GL_TEXTURE, 1,
area->x, area->y,
area->width, area->height);
glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &internal_format);
switch (internal_format)
{
case GL_RGB8:
format = GDK_MEMORY_R8G8B8;
gl_format = GL_RGB;
gl_type = GL_UNSIGNED_BYTE;
break;
case GL_RGBA8:
format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
gl_format = GL_RGBA;
gl_type = GL_UNSIGNED_BYTE;
break;
case GL_RGB16:
format = GDK_MEMORY_R16G16B16;
gl_format = GL_RGB;
gl_type = GL_UNSIGNED_SHORT;
break;
case GL_RGBA16:
format = GDK_MEMORY_R16G16B16A16_PREMULTIPLIED;
gl_format = GL_RGBA;
gl_type = GL_UNSIGNED_SHORT;
break;
case GL_RGB16F:
format = GDK_MEMORY_R16G16B16_FLOAT;
gl_format = GL_RGB;
gl_type = GL_HALF_FLOAT;
break;
case GL_RGBA16F:
format = GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED;
gl_format = GL_RGBA;
gl_type = GL_HALF_FLOAT;
break;
case GL_RGB32F:
format = GDK_MEMORY_R32G32B32_FLOAT;
gl_format = GL_RGB;
gl_type = GL_FLOAT;
break;
case GL_RGBA32F:
format = GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED;
gl_format = GL_RGBA;
gl_type = GL_FLOAT;
break;
default:
g_warning ("Texture in unexpected format 0x%X (%d). File a bug about adding it to GTK", internal_format, internal_format);
/* fallback to the dumbest possible format
* so that even age old GLES can do it */
format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
gl_format = GL_RGBA;
gl_type = GL_UNSIGNED_BYTE;
break;
}
stride = gdk_memory_format_bytes_per_pixel (format) * texture->width;
data = g_malloc (stride * texture->height);
gdk_gl_texture_get_tex_image (texture_,
gl_format,
gl_type,
data);
bytes = g_bytes_new_take (data, stride * texture->height);
*result = gdk_memory_texture_new (texture->width,
texture->height,
format,
bytes,
stride);
g_bytes_unref (bytes);
}
static GdkTexture *
gdk_gl_texture_download_texture (GdkTexture *texture)
{
GdkGLTexture *self = GDK_GL_TEXTURE (texture);
GdkTexture *result;
if (self->saved)
return g_object_ref (self->saved);
gdk_gl_texture_run (self, gdk_gl_texture_do_download_texture, &result);
return result;
}
static void
gdk_gl_texture_do_download (gpointer texture,
gpointer data)
{
glGetTexImage (GL_TEXTURE_2D,
0,
GL_BGRA,
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
GL_UNSIGNED_INT_8_8_8_8_REV,
#elif G_BYTE_ORDER == G_BIG_ENDIAN
GL_UNSIGNED_BYTE,
#else
#error "Unknown byte order for gdk_gl_texture_download()"
#endif
data);
}
static void
gdk_gl_texture_download (GdkTexture *texture,
guchar *data,
gsize stride)
{
GdkGLTexture *self = GDK_GL_TEXTURE (texture);
if (self->saved)
{
gdk_texture_download (self->saved, data, stride);
return;
}
cairo_destroy (cr);
cairo_surface_finish (surface);
cairo_surface_destroy (surface);
if (gdk_gl_context_get_use_es (self->context) ||
stride != texture->width * 4)
{
GDK_TEXTURE_CLASS (gdk_gl_texture_parent_class)->download (texture, data, stride);
return;
}
gdk_gl_texture_run (self, gdk_gl_texture_do_download, data);
}
static void
gdk_gl_texture_do_download_float (gpointer texture,
gpointer data)
{
glGetTexImage (GL_TEXTURE_2D,
0,
GL_RGBA,
GL_FLOAT,
data);
}
static void
gdk_gl_texture_download_float (GdkTexture *texture,
float *data,
gsize stride)
{
GdkGLTexture *self = GDK_GL_TEXTURE (texture);
if (self->saved)
{
gdk_texture_download_float (self->saved, data, stride);
return;
}
if (gdk_gl_context_get_use_es (self->context) ||
stride != texture->width * 4)
{
GDK_TEXTURE_CLASS (gdk_gl_texture_parent_class)->download_float (texture, data, stride);
return;
}
gdk_gl_texture_run (self, gdk_gl_texture_do_download_float, data);
}
static void
@@ -116,7 +325,9 @@ gdk_gl_texture_class_init (GdkGLTextureClass *klass)
GdkTextureClass *texture_class = GDK_TEXTURE_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
texture_class->download_texture = gdk_gl_texture_download_texture;
texture_class->download = gdk_gl_texture_download;
texture_class->download_float = gdk_gl_texture_download_float;
gobject_class->dispose = gdk_gl_texture_dispose;
}
@@ -150,24 +361,10 @@ gdk_gl_texture_get_id (GdkGLTexture *self)
void
gdk_gl_texture_release (GdkGLTexture *self)
{
GdkSurface *surface;
GdkTexture *texture;
cairo_t *cr;
g_return_if_fail (GDK_IS_GL_TEXTURE (self));
g_return_if_fail (self->saved == NULL);
texture = GDK_TEXTURE (self);
self->saved = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
texture->width, texture->height);
cr = cairo_create (self->saved);
surface = gdk_gl_context_get_surface (self->context);
gdk_cairo_draw_from_gl (cr, surface, self->id, GL_TEXTURE, 1, 0, 0,
texture->width, texture->height);
cairo_destroy (cr);
self->saved = gdk_texture_download_texture (GDK_TEXTURE (self));
if (self->destroy)
{

View File

@@ -17,12 +17,12 @@
#include "config.h"
#include "gtkhslaprivate.h"
#include "gdkhslaprivate.h"
#include <math.h>
void
_gtk_hsla_init_from_rgba (GtkHSLA *hsla,
_gdk_hsla_init_from_rgba (GdkHSLA *hsla,
const GdkRGBA *rgba)
{
float min;
@@ -31,21 +31,21 @@ _gtk_hsla_init_from_rgba (GtkHSLA *hsla,
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
@@ -57,25 +57,25 @@ _gtk_hsla_init_from_rgba (GtkHSLA *hsla,
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;
@@ -83,7 +83,7 @@ _gtk_hsla_init_from_rgba (GtkHSLA *hsla,
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;
@@ -92,22 +92,22 @@ _gtk_hsla_init_from_rgba (GtkHSLA *hsla,
void
_gdk_rgba_init_from_hsla (GdkRGBA *rgba,
const GtkHSLA *hsla)
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)
@@ -123,7 +123,7 @@ _gdk_rgba_init_from_hsla (GdkRGBA *rgba,
hue -= 360;
while (hue < 0)
hue += 360;
if (hue < 60)
rgba->red = m1 + (m2 - m1) * hue / 60;
else if (hue < 180)
@@ -132,13 +132,13 @@ _gdk_rgba_init_from_hsla (GdkRGBA *rgba,
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)
@@ -147,13 +147,13 @@ _gdk_rgba_init_from_hsla (GdkRGBA *rgba,
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)
@@ -166,8 +166,8 @@ _gdk_rgba_init_from_hsla (GdkRGBA *rgba,
}
void
_gtk_hsla_shade (GtkHSLA *dest,
const GtkHSLA *src,
_gdk_hsla_shade (GdkHSLA *dest,
const GdkHSLA *src,
float factor)
{
g_return_if_fail (dest != NULL);

View File

@@ -22,23 +22,23 @@
G_BEGIN_DECLS
typedef struct _GtkHSLA GtkHSLA;
typedef struct _GdkHSLA GdkHSLA;
struct _GtkHSLA {
struct _GdkHSLA {
float hue;
float saturation;
float lightness;
float alpha;
};
void _gtk_hsla_init_from_rgba (GtkHSLA *hsla,
void _gdk_hsla_init_from_rgba (GdkHSLA *hsla,
const GdkRGBA *rgba);
/* Yes, I can name that function like this! */
void _gdk_rgba_init_from_hsla (GdkRGBA *rgba,
const GtkHSLA *hsla);
const GdkHSLA *hsla);
void _gtk_hsla_shade (GtkHSLA *dest,
const GtkHSLA *src,
void _gdk_hsla_shade (GdkHSLA *dest,
const GdkHSLA *src,
float factor);
G_END_DECLS

View File

@@ -20,6 +20,7 @@
#include "config.h"
#include "gdkmemorytextureprivate.h"
#include "gsk/ngl/fp16private.h"
/**
* GdkMemoryTexture:
@@ -49,6 +50,10 @@ gdk_memory_format_bytes_per_pixel (GdkMemoryFormat format)
{
switch (format)
{
case GDK_MEMORY_R8G8B8:
case GDK_MEMORY_B8G8R8:
return 3;
case GDK_MEMORY_B8G8R8A8_PREMULTIPLIED:
case GDK_MEMORY_A8R8G8B8_PREMULTIPLIED:
case GDK_MEMORY_R8G8B8A8_PREMULTIPLIED:
@@ -58,9 +63,19 @@ gdk_memory_format_bytes_per_pixel (GdkMemoryFormat format)
case GDK_MEMORY_A8B8G8R8:
return 4;
case GDK_MEMORY_R8G8B8:
case GDK_MEMORY_B8G8R8:
return 3;
case GDK_MEMORY_R16G16B16:
case GDK_MEMORY_R16G16B16_FLOAT:
return 6;
case GDK_MEMORY_R16G16B16A16_PREMULTIPLIED:
case GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED:
return 8;
case GDK_MEMORY_R32G32B32_FLOAT:
return 12;
case GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED:
return 16;
case GDK_MEMORY_N_FORMATS:
default:
@@ -69,6 +84,41 @@ gdk_memory_format_bytes_per_pixel (GdkMemoryFormat format)
}
}
static gsize
gdk_memory_format_alignment (GdkMemoryFormat format)
{
switch (format)
{
case GDK_MEMORY_R8G8B8:
case GDK_MEMORY_B8G8R8:
case GDK_MEMORY_B8G8R8A8_PREMULTIPLIED:
case GDK_MEMORY_A8R8G8B8_PREMULTIPLIED:
case GDK_MEMORY_R8G8B8A8_PREMULTIPLIED:
case GDK_MEMORY_B8G8R8A8:
case GDK_MEMORY_A8R8G8B8:
case GDK_MEMORY_R8G8B8A8:
case GDK_MEMORY_A8B8G8R8:
return G_ALIGNOF (guchar);
case GDK_MEMORY_R16G16B16:
case GDK_MEMORY_R16G16B16_FLOAT:
return G_ALIGNOF (guint16);
case GDK_MEMORY_R16G16B16A16_PREMULTIPLIED:
case GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED:
return G_ALIGNOF (guint16);
case GDK_MEMORY_R32G32B32_FLOAT:
case GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED:
return G_ALIGNOF (float);
case GDK_MEMORY_N_FORMATS:
default:
g_assert_not_reached ();
return G_ALIGNOF (double);
}
}
static void
gdk_memory_texture_dispose (GObject *object)
{
@@ -79,22 +129,41 @@ gdk_memory_texture_dispose (GObject *object)
G_OBJECT_CLASS (gdk_memory_texture_parent_class)->dispose (object);
}
static GdkTexture *
gdk_memory_texture_download_texture (GdkTexture *texture)
{
return g_object_ref (texture);
}
static void
gdk_memory_texture_download (GdkTexture *texture,
const GdkRectangle *area,
guchar *data,
gsize stride)
gdk_memory_texture_download (GdkTexture *texture,
guchar *data,
gsize stride)
{
GdkMemoryTexture *self = GDK_MEMORY_TEXTURE (texture);
gdk_memory_convert (data, stride,
GDK_MEMORY_CAIRO_FORMAT_ARGB32,
(guchar *) g_bytes_get_data (self->bytes, NULL)
+ area->x * gdk_memory_format_bytes_per_pixel (self->format)
+ area->y * self->stride,
GDK_MEMORY_CONVERT_DOWNLOAD,
(guchar *) g_bytes_get_data (self->bytes, NULL),
self->stride,
self->format,
area->width, area->height);
gdk_texture_get_width (texture),
gdk_texture_get_height (texture));
}
static void
gdk_memory_texture_download_float (GdkTexture *texture,
float *data,
gsize stride)
{
GdkMemoryTexture *self = GDK_MEMORY_TEXTURE (texture);
gdk_memory_convert_to_float (data, stride,
(guchar *) g_bytes_get_data (self->bytes, NULL),
self->stride,
self->format,
gdk_texture_get_width (texture),
gdk_texture_get_height (texture));
}
static void
@@ -103,7 +172,9 @@ gdk_memory_texture_class_init (GdkMemoryTextureClass *klass)
GdkTextureClass *texture_class = GDK_TEXTURE_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
texture_class->download_texture = gdk_memory_texture_download_texture;
texture_class->download = gdk_memory_texture_download;
texture_class->download_float = gdk_memory_texture_download_float;
gobject_class->dispose = gdk_memory_texture_dispose;
}
@@ -112,6 +183,41 @@ gdk_memory_texture_init (GdkMemoryTexture *self)
{
}
static GBytes *
gdk_memory_sanitize (GBytes *bytes,
int width,
int height,
GdkMemoryFormat format,
gsize stride,
gsize *out_stride)
{
gsize align, size, copy_stride, bpp;
const guchar *data;
guchar *copy;
int y;
data = g_bytes_get_data (bytes, &size);
align = gdk_memory_format_alignment (format);
if (GPOINTER_TO_SIZE (data) % align == 0 &&
stride % align == 0)
{
*out_stride = stride;
return g_bytes_ref (bytes);
}
bpp = gdk_memory_format_bytes_per_pixel (format);
copy_stride = bpp * width;
/* align to multiples of 4, just to be sure */
copy_stride = (copy_stride + 3) & ~3;
copy = g_malloc (copy_stride * height);
for (y = 0; y < height; y++)
memcpy (copy + y * copy_stride, data + y * stride, bpp * width);
*out_stride = copy_stride;
return g_bytes_new_take (copy, copy_stride * height);
}
/**
* gdk_memory_texture_new:
* @width: the width of the texture
@@ -136,13 +242,20 @@ gdk_memory_texture_new (int width,
{
GdkMemoryTexture *self;
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
g_return_val_if_fail (bytes != NULL, NULL);
g_return_val_if_fail (stride >= width * gdk_memory_format_bytes_per_pixel (format), NULL);
bytes = gdk_memory_sanitize (bytes, width, height, format, stride, &stride);
self = g_object_new (GDK_TYPE_MEMORY_TEXTURE,
"width", width,
"height", height,
NULL);
self->format = format;
self->bytes = g_bytes_ref (bytes);
self->bytes = bytes;
self->stride = stride;
return GDK_TEXTURE (self);
@@ -283,6 +396,109 @@ SWIZZLE_PREMULTIPLY (3,0,1,2, 0,1,2,3)
SWIZZLE_PREMULTIPLY (3,0,1,2, 3,0,1,2)
SWIZZLE_PREMULTIPLY (3,0,1,2, 0,3,2,1)
#define CONVERT_FUNC(name,suffix,R,G,B,A,step) \
static void \
convert_ ## name ## _to_ ## suffix (guchar *dest_data, \
gsize dest_stride, \
const guchar *src_data, \
gsize src_stride, \
gsize width, \
gsize height) \
{ \
gsize x, y; \
\
for (y = 0; y < height; y++) \
{ \
for (x = 0; x < width; x++) \
{ \
guchar conv[4]; \
convert_pixel_ ## name (conv, src_data + step * x); \
dest_data[4 * x + R] = conv[0]; \
dest_data[4 * x + G] = conv[1]; \
dest_data[4 * x + B] = conv[2]; \
dest_data[4 * x + A] = conv[3]; \
} \
\
dest_data += dest_stride; \
src_data += src_stride; \
} \
}
#define CONVERT_FUNCS(name,step) \
CONVERT_FUNC(name, download_le, 2, 1, 0, 3, step) \
CONVERT_FUNC(name, download_be, 1, 2, 3, 0, step) \
CONVERT_FUNC(name, gles_rgba, 0, 1, 2, 3, step) \
static inline void
convert_pixel_rgb16 (guchar *dest_data, const guchar *src_data)
{
const guint16 *src = (const guint16 *) src_data;
dest_data[0] = (guchar)(src[0] >> 8);
dest_data[1] = (guchar)(src[1] >> 8);
dest_data[2] = (guchar)(src[2] >> 8);
dest_data[3] = 0xFF;
}
CONVERT_FUNCS(rgb16, 3 * sizeof (guint16))
static inline void
convert_pixel_rgba16 (guchar *dest_data, const guchar *src_data)
{
const guint16 *src = (const guint16 *) src_data;
dest_data[0] = (guchar)(src[0] >> 8);
dest_data[1] = (guchar)(src[1] >> 8);
dest_data[2] = (guchar)(src[2] >> 8);
dest_data[3] = (guchar)(src[3] >> 8);
}
CONVERT_FUNCS(rgba16, 4 * sizeof (guint16))
static inline void
convert_pixel_rgb16f (guchar *dest_data, const guchar *src_data)
{
float src[4];
guint16 tmp[4];
memcpy(tmp, src_data, sizeof(guint16) * 3);
half_to_float4(tmp, src);
dest_data[0] = CLAMP (src[0] * 256.f, 0.f, 255.f);
dest_data[1] = CLAMP (src[1] * 256.f, 0.f, 255.f);
dest_data[2] = CLAMP (src[2] * 256.f, 0.f, 255.f);
dest_data[3] = 0xFF;
}
CONVERT_FUNCS(rgb16f, 3 * sizeof (guint16))
static inline void
convert_pixel_rgba16f (guchar *dest_data, const guchar *src_data)
{
float src[4];
half_to_float4((const guint16 *) src_data, src);
dest_data[0] = CLAMP (src[0] * 256.f, 0.f, 255.f);
dest_data[1] = CLAMP (src[1] * 256.f, 0.f, 255.f);
dest_data[2] = CLAMP (src[2] * 256.f, 0.f, 255.f);
dest_data[3] = CLAMP (src[3] * 256.f, 0.f, 255.f);
}
CONVERT_FUNCS(rgba16f, 4 * sizeof (guint16))
static inline void
convert_pixel_rgb32f (guchar *dest_data, const guchar *src_data)
{
float *src = (float *) src_data;
dest_data[0] = CLAMP (src[0] * 256.f, 0.f, 255.f);
dest_data[1] = CLAMP (src[1] * 256.f, 0.f, 255.f);
dest_data[2] = CLAMP (src[2] * 256.f, 0.f, 255.f);
dest_data[3] = 0xFF;
}
CONVERT_FUNCS(rgb32f, 3 * sizeof (float))
static inline void
convert_pixel_rgba32f (guchar *dest_data, const guchar *src_data)
{
float *src = (float *) src_data;
dest_data[0] = CLAMP (src[0] * 256.f, 0.f, 255.f);
dest_data[1] = CLAMP (src[1] * 256.f, 0.f, 255.f);
dest_data[2] = CLAMP (src[2] * 256.f, 0.f, 255.f);
dest_data[3] = CLAMP (src[3] * 256.f, 0.f, 255.f);
}
CONVERT_FUNCS(rgba32f, 4 * sizeof (float))
typedef void (* ConversionFunc) (guchar *dest_data,
gsize dest_stride,
const guchar *src_data,
@@ -290,7 +506,7 @@ typedef void (* ConversionFunc) (guchar *dest_data,
gsize width,
gsize height);
static ConversionFunc converters[GDK_MEMORY_N_FORMATS][3] =
static ConversionFunc converters[GDK_MEMORY_N_FORMATS][GDK_MEMORY_N_CONVERSIONS] =
{
{ convert_memcpy, convert_swizzle3210, convert_swizzle2103 },
{ convert_swizzle3210, convert_memcpy, convert_swizzle3012 },
@@ -300,21 +516,192 @@ static ConversionFunc converters[GDK_MEMORY_N_FORMATS][3] =
{ convert_swizzle_premultiply_3210_3012, convert_swizzle_premultiply_0123_3012, convert_swizzle_premultiply_3012_3012 },
{ convert_swizzle_premultiply_3210_0321, convert_swizzle_premultiply_0123_0321, convert_swizzle_premultiply_3012_0321 },
{ convert_swizzle_opaque_3210, convert_swizzle_opaque_0123, convert_swizzle_opaque_3012 },
{ convert_swizzle_opaque_3012, convert_swizzle_opaque_0321, convert_swizzle_opaque_3210 }
{ convert_swizzle_opaque_3012, convert_swizzle_opaque_0321, convert_swizzle_opaque_3210 },
{ convert_rgb16_to_download_le, convert_rgb16_to_download_be, convert_rgb16_to_gles_rgba },
{ convert_rgba16_to_download_le, convert_rgba16_to_download_be, convert_rgba16_to_gles_rgba },
{ convert_rgb16f_to_download_le, convert_rgb16f_to_download_be, convert_rgb16f_to_gles_rgba },
{ convert_rgba16f_to_download_le, convert_rgba16f_to_download_be, convert_rgba16f_to_gles_rgba },
{ convert_rgb32f_to_download_le, convert_rgb32f_to_download_be, convert_rgb32f_to_gles_rgba },
{ convert_rgba32f_to_download_le, convert_rgba32f_to_download_be, convert_rgba32f_to_gles_rgba }
};
void
gdk_memory_convert (guchar *dest_data,
gsize dest_stride,
GdkMemoryFormat dest_format,
const guchar *src_data,
gsize src_stride,
GdkMemoryFormat src_format,
gsize width,
gsize height)
gdk_memory_convert (guchar *dest_data,
gsize dest_stride,
GdkMemoryConversion dest_format,
const guchar *src_data,
gsize src_stride,
GdkMemoryFormat src_format,
gsize width,
gsize height)
{
g_assert (dest_format < 3);
g_assert (src_format < GDK_MEMORY_N_FORMATS);
converters[src_format][dest_format] (dest_data, dest_stride, src_data, src_stride, width, height);
}
#define CONVERT_FLOAT(R,G,B,A,premultiply) G_STMT_START {\
for (y = 0; y < height; y++) \
{ \
for (x = 0; x < width; x++) \
{ \
if (A >= 0) \
{ \
dest_data[4 * x + 0] = src_data[4 * x + R] / 255.0f; \
dest_data[4 * x + 1] = src_data[4 * x + G] / 255.0f; \
dest_data[4 * x + 2] = src_data[4 * x + B] / 255.0f; \
dest_data[4 * x + 3] = src_data[4 * x + A] / 255.0f; \
if (premultiply) \
{ \
dest_data[4 * x + 0] *= dest_data[4 * x + 3]; \
dest_data[4 * x + 1] *= dest_data[4 * x + 3]; \
dest_data[4 * x + 2] *= dest_data[4 * x + 3]; \
} \
} \
else \
{ \
dest_data[4 * x + 0] = src_data[3 * x + R] / 255.0f; \
dest_data[4 * x + 1] = src_data[3 * x + G] / 255.0f; \
dest_data[4 * x + 2] = src_data[3 * x + B] / 255.0f; \
dest_data[4 * x + 3] = 1.0; \
} \
} \
\
dest_data += dest_stride; \
src_data += src_stride; \
} \
}G_STMT_END
#define CONVERT_FLOAT_PIXEL(func,step) G_STMT_START{\
for (y = 0; y < height; y++) \
{ \
for (x = 0; x < width; x++) \
{ \
func (dest_data + 4 * x, src_data + step * x); \
} \
\
dest_data += dest_stride; \
src_data += src_stride; \
} \
}G_STMT_END
static inline void
convert_rgb16_to_float (float *dest, const guchar *src_data)
{
const guint16 *src = (const guint16 *) src_data;
dest[0] = src[0] / 65535.f;
dest[1] = src[1] / 65535.f;
dest[2] = src[2] / 65535.f;
dest[3] = 1.0;
}
static inline void
convert_rgba16_to_float (float *dest, const guchar *src_data)
{
const guint16 *src = (const guint16 *) src_data;
dest[0] = src[0] / 65535.f;
dest[1] = src[1] / 65535.f;
dest[2] = src[2] / 65535.f;
dest[3] = src[3] / 65535.f;
}
static inline void
convert_rgb16f_to_float (float *dest, const guchar *src_data)
{
guint16 tmp[4];
memcpy(tmp, src_data, sizeof(guint16) * 3);
tmp[3] = FP16_ONE;
half_to_float4 (tmp, dest);
}
static inline void
convert_rgba16f_to_float (float *dest, const guchar *src_data)
{
half_to_float4 ((const guint16 *) src_data, dest);
}
static inline void
convert_rgb32f_to_float (float *dest, const guchar *src_data)
{
const float *src = (const float *) src_data;
dest[0] = src[0];
dest[1] = src[1];
dest[2] = src[2];
dest[3] = 1.0;
}
static inline void
convert_rgba32f_to_float (float *dest, const guchar *src_data)
{
const float *src = (const float *) src_data;
dest[0] = src[0];
dest[1] = src[1];
dest[2] = src[2];
dest[3] = src[3];
}
void
gdk_memory_convert_to_float (float *dest_data,
gsize dest_stride,
const guchar *src_data,
gsize src_stride,
GdkMemoryFormat src_format,
gsize width,
gsize height)
{
gsize x, y;
switch (src_format)
{
case GDK_MEMORY_B8G8R8A8_PREMULTIPLIED:
CONVERT_FLOAT (2, 1, 0, 3, FALSE);
break;
case GDK_MEMORY_A8R8G8B8_PREMULTIPLIED:
CONVERT_FLOAT (1, 2, 3, 0, FALSE);
break;
case GDK_MEMORY_R8G8B8A8_PREMULTIPLIED:
CONVERT_FLOAT (0, 1, 2, 3, FALSE);
break;
case GDK_MEMORY_B8G8R8A8:
CONVERT_FLOAT (2, 1, 0, 3, TRUE);
break;
case GDK_MEMORY_A8R8G8B8:
CONVERT_FLOAT (1, 2, 3, 0, TRUE);
break;
case GDK_MEMORY_R8G8B8A8:
CONVERT_FLOAT (0, 1, 2, 3, TRUE);
break;
case GDK_MEMORY_A8B8G8R8:
CONVERT_FLOAT (3, 2, 1, 0, TRUE);
break;
case GDK_MEMORY_R8G8B8:
CONVERT_FLOAT (0, 1, 2, -1, FALSE);
break;
case GDK_MEMORY_B8G8R8:
CONVERT_FLOAT (2, 1, 0, -1, FALSE);
break;
case GDK_MEMORY_R16G16B16:
CONVERT_FLOAT_PIXEL (convert_rgb16_to_float, 3 * sizeof (guint16));
break;
case GDK_MEMORY_R16G16B16A16_PREMULTIPLIED:
CONVERT_FLOAT_PIXEL (convert_rgba16_to_float, 4 * sizeof (guint16));
break;
case GDK_MEMORY_R16G16B16_FLOAT:
CONVERT_FLOAT_PIXEL (convert_rgb16f_to_float, 3 * sizeof (guint16));
break;
case GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED:
CONVERT_FLOAT_PIXEL (convert_rgba16f_to_float, 4 * sizeof (guint16));
break;
case GDK_MEMORY_R32G32B32_FLOAT:
CONVERT_FLOAT_PIXEL (convert_rgb32f_to_float, 3 * sizeof (float));
break;
case GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED:
CONVERT_FLOAT_PIXEL (convert_rgba32f_to_float, 4 * sizeof (float));
break;
case GDK_MEMORY_N_FORMATS:
default:
g_assert_not_reached();
}
}

View File

@@ -42,6 +42,20 @@ G_BEGIN_DECLS
* @GDK_MEMORY_A8B8G8R8: 4 bytes; for alpha, blue, green, red.
* @GDK_MEMORY_R8G8B8: 3 bytes; for red, green, blue. The data is opaque.
* @GDK_MEMORY_B8G8R8: 3 bytes; for blue, green, red. The data is opaque.
* @GDK_MEMORY_R16G16B16: 3 guint16 values; for red, green, blue. Since 4.6
* @GDK_MEMORY_R16G16B16A16_PREMULTIPLIED: 4 guint16 values; for red, green,
* blue, alpha. The color values are premultiplied with the alpha value.
* Since 4.6
* @GDK_MEMORY_R16G16B16_FLOAT: 3 half-float values; for red, green, blue.
* The data is opaque. Since 4.6
* @GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED: 4 half-float values; for
* red, green, blue and alpha. The color values are premultiplied with
* the alpha value. Since 4.6
* @GDK_MEMORY_B32G32R32_FLOAT: 3 float values; for blue, green, red.
* The data is opaque. Since 4.6
* @GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED: 4 float values; for
* red, green, blue and alpha. The color values are premultiplied with
* the alpha value. Since 4.6
* @GDK_MEMORY_N_FORMATS: The number of formats. This value will change as
* more formats get added, so do not rely on its concrete integer.
*
@@ -67,6 +81,12 @@ typedef enum {
GDK_MEMORY_A8B8G8R8,
GDK_MEMORY_R8G8B8,
GDK_MEMORY_B8G8R8,
GDK_MEMORY_R16G16B16,
GDK_MEMORY_R16G16B16A16_PREMULTIPLIED,
GDK_MEMORY_R16G16B16_FLOAT,
GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED,
GDK_MEMORY_R32G32B32_FLOAT,
GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED,
GDK_MEMORY_N_FORMATS
} GdkMemoryFormat;

View File

@@ -29,7 +29,21 @@ G_BEGIN_DECLS
#define GDK_MEMORY_GDK_PIXBUF_OPAQUE GDK_MEMORY_R8G8B8
#define GDK_MEMORY_GDK_PIXBUF_ALPHA GDK_MEMORY_R8G8B8A8
#define GDK_MEMORY_CAIRO_FORMAT_ARGB32 GDK_MEMORY_DEFAULT
typedef enum {
GDK_MEMORY_CONVERT_DOWNLOAD_LITTLE_ENDIAN,
GDK_MEMORY_CONVERT_DOWNLOAD_BIT_ENDIAN,
GDK_MEMORY_CONVERT_GLES_RGBA,
GDK_MEMORY_N_CONVERSIONS
} GdkMemoryConversion;
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
#define GDK_MEMORY_CONVERT_DOWNLOAD GDK_MEMORY_CONVERT_DOWNLOAD_LITTLE_ENDIAN
#elif G_BYTE_ORDER == G_BIG_ENDIAN
#define GDK_MEMORY_CONVERT_DOWNLOAD GDK_MEMORY_CONVERT_DOWNLOAD_BIG_ENDIAN
#else
#error "Unknown byte order for GDK_MEMORY_CONVERT_DOWNLOAD"
#endif
gsize gdk_memory_format_bytes_per_pixel (GdkMemoryFormat format);
@@ -37,14 +51,22 @@ GdkMemoryFormat gdk_memory_texture_get_format (GdkMemoryTexture *
const guchar * gdk_memory_texture_get_data (GdkMemoryTexture *self);
gsize gdk_memory_texture_get_stride (GdkMemoryTexture *self);
void gdk_memory_convert (guchar *dest_data,
gsize dest_stride,
GdkMemoryFormat dest_format,
const guchar *src_data,
gsize src_stride,
GdkMemoryFormat src_format,
gsize width,
gsize height);
void gdk_memory_convert (guchar *dest_data,
gsize dest_stride,
GdkMemoryConversion dest_format,
const guchar *src_data,
gsize src_stride,
GdkMemoryFormat src_format,
gsize width,
gsize height);
void gdk_memory_convert_to_float (float *dest_data,
gsize dest_stride,
const guchar *src_data,
gsize src_stride,
GdkMemoryFormat src_format,
gsize width,
gsize height);
G_END_DECLS

View File

@@ -70,17 +70,17 @@ typedef enum {
* snapshot at or 0 if none. This is purely a hint. The object must still
* be able to render at any size.
* @get_intrinsic_aspect_ratio: The preferred aspect ratio for this object
* or 0 if none. If both [vfunc@Gdk.PaintableInterface.get_intrinsic_width]
* and [vfunc@Gdk.PaintableInterface.get_intrinsic_height] return non-zero
* or 0 if none. If both [vfunc@Gdk.Paintable.get_intrinsic_width]
* and [vfunc@Gdk.Paintable.get_intrinsic_height] return non-zero
* values, this function should return the aspect ratio computed from those.
*
* The list of functions that can be implemented for the `GdkPaintable`
* interface.
*
* Note that apart from the [vfunc@Gdk.PaintableInterface.snapshot] function,
* Note that apart from the [vfunc@Gdk.Paintable.snapshot] function,
* no virtual function of this interface is mandatory to implement, though it
* is a good idea to implement [vfunc@Gdk.PaintableInterface.get_current_image]
* for non-static paintables and [vfunc@Gdk.PaintableInterface.get_flags] if the
* is a good idea to implement [vfunc@Gdk.Paintable.get_current_image]
* for non-static paintables and [vfunc@Gdk.Paintable.get_flags] if the
* image is not dynamic as the default implementation returns no flags and
* that will make the implementation likely quite slow.
*/

View File

@@ -30,6 +30,7 @@
#include <errno.h>
#include <math.h>
#include "gdkhslaprivate.h"
G_DEFINE_BOXED_TYPE (GdkRGBA, gdk_rgba,
gdk_rgba_copy, gdk_rgba_free)
@@ -186,6 +187,7 @@ gdk_rgba_parse (GdkRGBA *rgba,
const char *spec)
{
gboolean has_alpha;
gboolean is_hsl;
double r, g, b, a;
char *str = (char *) spec;
char *p;
@@ -196,11 +198,26 @@ gdk_rgba_parse (GdkRGBA *rgba,
if (strncmp (str, "rgba", 4) == 0)
{
has_alpha = TRUE;
is_hsl = FALSE;
str += 4;
}
else if (strncmp (str, "rgb", 3) == 0)
{
has_alpha = FALSE;
is_hsl = FALSE;
a = 1;
str += 3;
}
else if (strncmp (str, "hsla", 4) == 0)
{
has_alpha = TRUE;
is_hsl = TRUE;
str += 4;
}
else if (strncmp (str, "hsl", 3) == 0)
{
has_alpha = FALSE;
is_hsl = TRUE;
a = 1;
str += 3;
}
@@ -291,10 +308,22 @@ gdk_rgba_parse (GdkRGBA *rgba,
if (rgba)
{
rgba->red = CLAMP (r, 0, 1);
rgba->green = CLAMP (g, 0, 1);
rgba->blue = CLAMP (b, 0, 1);
rgba->alpha = CLAMP (a, 0, 1);
if (is_hsl)
{
GdkHSLA hsla;
hsla.hue = r * 255;
hsla.saturation = CLAMP (g, 0, 1);
hsla.lightness = CLAMP (b, 0, 1);
hsla.alpha = CLAMP (a, 0, 1);
_gdk_rgba_init_from_hsla (rgba, &hsla);
}
else
{
rgba->red = CLAMP (r, 0, 1);
rgba->green = CLAMP (g, 0, 1);
rgba->blue = CLAMP (b, 0, 1);
rgba->alpha = CLAMP (a, 0, 1);
}
}
return TRUE;
@@ -462,6 +491,47 @@ parse_color_channel (GtkCssParser *parser,
}
}
static guint
parse_hsla_color_channel (GtkCssParser *parser,
guint arg,
gpointer data)
{
GdkHSLA *hsla = data;
double dvalue;
switch (arg)
{
case 0:
if (!gtk_css_parser_consume_number (parser, &dvalue))
return 0;
hsla->hue = dvalue;
return 1;
case 1:
if (!gtk_css_parser_consume_percentage (parser, &dvalue))
return 0;
hsla->saturation = CLAMP (dvalue, 0.0, 100.0) / 100.0;
return 1;
case 2:
if (!gtk_css_parser_consume_percentage (parser, &dvalue))
return 0;
hsla->lightness = CLAMP (dvalue, 0.0, 100.0) / 100.0;
return 1;
case 3:
if (!gtk_css_parser_consume_number (parser, &dvalue))
return 0;
hsla->alpha = CLAMP (dvalue, 0.0, 1.0) / 1.0;
return 1;
default:
g_assert_not_reached ();
return 0;
}
}
static gboolean
rgba_init_chars (GdkRGBA *rgba,
const char s[8])
@@ -501,6 +571,18 @@ gdk_rgba_parser_parse (GtkCssParser *parser,
{
return gtk_css_parser_consume_function (parser, 4, 4, parse_color_channel, rgba);
}
else if (gtk_css_token_is_function (token, "hsl") || gtk_css_token_is_function (token, "hsla"))
{
GdkHSLA hsla;
hsla.alpha = 1.0;
if (!gtk_css_parser_consume_function (parser, 3, 4, parse_hsla_color_channel, &hsla))
return FALSE;
_gdk_rgba_init_from_hsla (rgba, &hsla);
return TRUE;
}
else if (gtk_css_token_is (token, GTK_CSS_TOKEN_HASH_ID) ||
gtk_css_token_is (token, GTK_CSS_TOKEN_HASH_UNRESTRICTED))
{

View File

@@ -67,7 +67,7 @@ GDK_AVAILABLE_IN_ALL
gboolean gdk_rgba_parse (GdkRGBA *rgba,
const char *spec);
GDK_AVAILABLE_IN_ALL
char * gdk_rgba_to_string (const GdkRGBA *rgba);
char * gdk_rgba_to_string (const GdkRGBA *rgba) G_GNUC_MALLOC;
G_END_DECLS

View File

@@ -1065,87 +1065,23 @@ gdk_surface_get_mapped (GdkSurface *surface)
return GDK_SURFACE_IS_MAPPED (surface);
}
GdkGLContext *
gdk_surface_get_shared_data_gl_context (GdkSurface *surface)
{
static int in_shared_data_creation;
GdkDisplay *display;
GdkGLContext *context;
if (in_shared_data_creation)
return NULL;
in_shared_data_creation = 1;
display = gdk_surface_get_display (surface);
context = (GdkGLContext *)g_object_get_data (G_OBJECT (display), "gdk-gl-shared-data-context");
if (context == NULL)
{
GError *error = NULL;
context = GDK_SURFACE_GET_CLASS (surface)->create_gl_context (surface, FALSE, NULL, &error);
if (context == NULL)
{
g_warning ("Failed to create shared context: %s", error->message);
g_clear_error (&error);
}
gdk_gl_context_realize (context, &error);
if (context == NULL)
{
g_warning ("Failed to realize shared context: %s", error->message);
g_clear_error (&error);
}
g_object_set_data (G_OBJECT (display), "gdk-gl-shared-data-context", context);
}
in_shared_data_creation = 0;
return context;
}
GdkGLContext *
gdk_surface_get_paint_gl_context (GdkSurface *surface,
GError **error)
GError **error)
{
GError *internal_error = NULL;
if (GDK_DISPLAY_DEBUG_CHECK (surface->display, GL_DISABLE))
{
g_set_error_literal (error, GDK_GL_ERROR,
GDK_GL_ERROR_NOT_AVAILABLE,
_("GL support disabled via GDK_DEBUG"));
return NULL;
}
if (!gdk_display_prepare_gl (surface->display, error))
return NULL;
if (surface->gl_paint_context == NULL)
{
GdkSurfaceClass *class = GDK_SURFACE_GET_CLASS (surface);
if (class->create_gl_context == NULL)
{
g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
_("The current backend does not support OpenGL"));
return NULL;
}
surface->gl_paint_context =
class->create_gl_context (surface, TRUE, NULL, &internal_error);
surface->gl_paint_context = gdk_surface_create_gl_context (surface, error);
if (surface->gl_paint_context == NULL)
return NULL;
}
if (internal_error != NULL)
if (!gdk_gl_context_realize (surface->gl_paint_context, error))
{
g_propagate_error (error, internal_error);
g_clear_object (&(surface->gl_paint_context));
return NULL;
}
gdk_gl_context_realize (surface->gl_paint_context, &internal_error);
if (internal_error != NULL)
{
g_propagate_error (error, internal_error);
g_clear_object (&(surface->gl_paint_context));
g_clear_object (&surface->gl_paint_context);
return NULL;
}
@@ -1170,19 +1106,13 @@ GdkGLContext *
gdk_surface_create_gl_context (GdkSurface *surface,
GError **error)
{
GdkGLContext *paint_context;
g_return_val_if_fail (GDK_IS_SURFACE (surface), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
paint_context = gdk_surface_get_paint_gl_context (surface, error);
if (paint_context == NULL)
if (!gdk_display_prepare_gl (surface->display, error))
return NULL;
return GDK_SURFACE_GET_CLASS (surface)->create_gl_context (surface,
FALSE,
paint_context,
error);
return gdk_gl_context_new_for_surface (surface);
}
/**

View File

@@ -160,10 +160,6 @@ struct _GdkSurfaceClass
void (* set_opaque_region) (GdkSurface *surface,
cairo_region_t *region);
GdkGLContext *(*create_gl_context) (GdkSurface *surface,
gboolean attached,
GdkGLContext *share,
GError **error);
void (* request_layout) (GdkSurface *surface);
gboolean (* compute_size) (GdkSurface *surface);
};
@@ -266,7 +262,6 @@ void _gdk_surface_update_size (GdkSurface *surface);
GdkGLContext * gdk_surface_get_paint_gl_context (GdkSurface *surface,
GError **error);
GdkGLContext * gdk_surface_get_shared_data_gl_context (GdkSurface *surface);
gboolean gdk_surface_handle_event (GdkEvent *event);
GdkSeat * gdk_surface_get_seat_from_event (GdkSurface *surface,

View File

@@ -28,8 +28,8 @@
* `GdkPixbuf`, or a Cairo surface, or other pixel data.
*
* The ownership of the pixel data is transferred to the `GdkTexture`
* instance; you can only make a copy of it, via
* [method@Gdk.Texture.download].
* instance; you can only make a copy of it, via [method@Gdk.Texture.download]
* or [method@Gdk.Texture.download_float].
*
* `GdkTexture` is an immutable object: That means you cannot change
* anything about it other than increasing the reference count via
@@ -41,11 +41,17 @@
#include "gdktextureprivate.h"
#include "gdkinternals.h"
#include "gdkintl.h"
#include "gdkmemorytextureprivate.h"
#include "gdkpaintable.h"
#include "gdksnapshot.h"
#include <graphene.h>
#include "loaders/gdkpngprivate.h"
#include "loaders/gdktiffprivate.h"
#include "loaders/gdkjpegprivate.h"
G_DEFINE_QUARK (gdk-texture-error-quark, gdk_texture_error)
/* HACK: So we don't need to include any (not-yet-created) GSK or GTK headers */
void
@@ -108,20 +114,143 @@ gdk_texture_paintable_init (GdkPaintableInterface *iface)
iface->get_intrinsic_height = gdk_texture_paintable_get_intrinsic_height;
}
static GVariant *
gdk_texture_icon_serialize (GIcon *icon)
{
GVariant *result;
GBytes *bytes;
bytes = gdk_texture_save_to_png_bytes (GDK_TEXTURE (icon));
result = g_variant_new_from_bytes (G_VARIANT_TYPE_BYTESTRING, bytes, TRUE);
g_bytes_unref (bytes);
return g_variant_new ("(sv)", "bytes", result);
}
static void
gdk_texture_icon_init (GIconIface *iface)
{
iface->hash = (guint (*) (GIcon *)) g_direct_hash;
iface->equal = (gboolean (*) (GIcon *, GIcon *)) g_direct_equal;
iface->serialize = gdk_texture_icon_serialize;
}
static GInputStream *
gdk_texture_loadable_icon_load (GLoadableIcon *icon,
int size,
char **type,
GCancellable *cancellable,
GError **error)
{
GInputStream *stream;
GBytes *bytes;
bytes = gdk_texture_save_to_png_bytes (GDK_TEXTURE (icon));
stream = g_memory_input_stream_new_from_bytes (bytes);
g_bytes_unref (bytes);
if (type)
*type = NULL;
return stream;
}
static void
gdk_texture_loadable_icon_load_in_thread (GTask *task,
gpointer source_object,
gpointer task_data,
GCancellable *cancellable)
{
GInputStream *stream;
GBytes *bytes;
bytes = gdk_texture_save_to_png_bytes (source_object);
stream = g_memory_input_stream_new_from_bytes (bytes);
g_bytes_unref (bytes);
g_task_return_pointer (task, stream, g_object_unref);
}
static void
gdk_texture_loadable_icon_load_async (GLoadableIcon *icon,
int size,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GTask *task;
task = g_task_new (icon, cancellable, callback, user_data);
g_task_run_in_thread (task, gdk_texture_loadable_icon_load_in_thread);
g_object_unref (task);
}
static GInputStream *
gdk_texture_loadable_icon_load_finish (GLoadableIcon *icon,
GAsyncResult *res,
char **type,
GError **error)
{
GInputStream *result;
g_return_val_if_fail (g_task_is_valid (res, icon), NULL);
result = g_task_propagate_pointer (G_TASK (res), error);
if (result == NULL)
return NULL;
if (type)
*type = NULL;
return result;
}
static void
gdk_texture_loadable_icon_init (GLoadableIconIface *iface)
{
iface->load = gdk_texture_loadable_icon_load;
iface->load_async = gdk_texture_loadable_icon_load_async;
iface->load_finish = gdk_texture_loadable_icon_load_finish;
}
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GdkTexture, gdk_texture, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE,
gdk_texture_paintable_init))
gdk_texture_paintable_init)
G_IMPLEMENT_INTERFACE (G_TYPE_ICON,
gdk_texture_icon_init)
G_IMPLEMENT_INTERFACE (G_TYPE_LOADABLE_ICON, gdk_texture_loadable_icon_init))
#define GDK_TEXTURE_WARN_NOT_IMPLEMENTED_METHOD(obj,method) \
g_critical ("Texture of type '%s' does not implement GdkTexture::" # method, G_OBJECT_TYPE_NAME (obj))
static void
gdk_texture_real_download (GdkTexture *self,
const GdkRectangle *area,
guchar *data,
gsize stride)
static GdkTexture *
gdk_texture_real_download_texture (GdkTexture *self)
{
GDK_TEXTURE_WARN_NOT_IMPLEMENTED_METHOD (self, download);
GDK_TEXTURE_WARN_NOT_IMPLEMENTED_METHOD (self, download_texture);
return NULL;
}
static void
gdk_texture_real_download (GdkTexture *texture,
guchar *data,
gsize stride)
{
GdkTexture *memory_texture;
memory_texture = gdk_texture_download_texture (texture);
gdk_texture_download (memory_texture, data, stride);
g_object_unref (memory_texture);
}
static void
gdk_texture_real_download_float (GdkTexture *self,
float *data,
gsize stride)
{
GdkTexture *memory_texture;
memory_texture = gdk_texture_download_texture (self);
gdk_texture_download_float (memory_texture, data, stride);
g_object_unref (memory_texture);
}
static void
@@ -187,7 +316,9 @@ gdk_texture_class_init (GdkTextureClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
klass->download_texture = gdk_texture_real_download_texture;
klass->download = gdk_texture_real_download;
klass->download_float = gdk_texture_real_download_float;
gobject_class->set_property = gdk_texture_set_property;
gobject_class->get_property = gdk_texture_get_property;
@@ -263,7 +394,7 @@ gdk_texture_new_for_surface (cairo_surface_t *surface)
texture = gdk_memory_texture_new (cairo_image_surface_get_width (surface),
cairo_image_surface_get_height (surface),
GDK_MEMORY_CAIRO_FORMAT_ARGB32,
GDK_MEMORY_DEFAULT,
bytes,
cairo_image_surface_get_stride (surface));
@@ -325,18 +456,23 @@ gdk_texture_new_for_pixbuf (GdkPixbuf *pixbuf)
GdkTexture *
gdk_texture_new_from_resource (const char *resource_path)
{
GError *error = NULL;
GBytes *bytes;
GdkTexture *texture;
GdkPixbuf *pixbuf;
GError *error = NULL;
g_return_val_if_fail (resource_path != NULL, NULL);
pixbuf = gdk_pixbuf_new_from_resource (resource_path, &error);
if (pixbuf == NULL)
g_error ("Resource path %s is not a valid image: %s", resource_path, error->message);
bytes = g_resources_lookup_data (resource_path, 0, &error);
if (bytes != NULL)
{
texture = gdk_texture_new_from_bytes (bytes, &error);
g_bytes_unref (bytes);
}
else
texture = NULL;
texture = gdk_texture_new_for_pixbuf (pixbuf);
g_object_unref (pixbuf);
if (texture == NULL)
g_error ("Resource path %s s not a valid image: %s", resource_path, error->message);
return texture;
}
@@ -359,17 +495,65 @@ GdkTexture *
gdk_texture_new_from_file (GFile *file,
GError **error)
{
GBytes *bytes;
GdkTexture *texture;
GdkPixbuf *pixbuf;
GInputStream *stream;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
stream = G_INPUT_STREAM (g_file_read (file, NULL, error));
if (stream == NULL)
bytes = g_file_load_bytes (file, NULL, NULL, error);
if (bytes == NULL)
return NULL;
texture = gdk_texture_new_from_bytes (bytes, error);
g_bytes_unref (bytes);
return texture;
}
gboolean
gdk_texture_can_load (GBytes *bytes)
{
return gdk_is_png (bytes) ||
gdk_is_jpeg (bytes) ||
gdk_is_tiff (bytes);
}
static GdkTexture *
gdk_texture_new_from_bytes_internal (GBytes *bytes,
GError **error)
{
if (gdk_is_png (bytes))
{
return gdk_load_png (bytes, error);
}
else if (gdk_is_jpeg (bytes))
{
return gdk_load_jpeg (bytes, error);
}
else if (gdk_is_tiff (bytes))
{
return gdk_load_tiff (bytes, error);
}
else
{
g_set_error_literal (error,
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_UNSUPPORTED_FORMAT,
_("Unknown image format."));
return NULL;
}
}
static GdkTexture *
gdk_texture_new_from_bytes_pixbuf (GBytes *bytes,
GError **error)
{
GInputStream *stream;
GdkPixbuf *pixbuf;
GdkTexture *texture;
stream = g_memory_input_stream_new_from_bytes (bytes);
pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error);
g_object_unref (stream);
if (pixbuf == NULL)
@@ -381,6 +565,82 @@ gdk_texture_new_from_file (GFile *file,
return texture;
}
/**
* gdk_texture_new_from_bytes:
* @bytes: a `GBytes` containing the data to load
* @error: Return location for an error
*
* Creates a new texture by loading an image from memory,
*
* The file format is detected automatically. The supported formats
* are PNG and JPEG, though more formats might be available.
*
* If %NULL is returned, then @error will be set.
*
* Return value: A newly-created `GdkTexture`
*
* Since: 4.6
*/
GdkTexture *
gdk_texture_new_from_bytes (GBytes *bytes,
GError **error)
{
GdkTexture *texture;
GError *internal_error = NULL;
g_return_val_if_fail (bytes != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
texture = gdk_texture_new_from_bytes_internal (bytes, &internal_error);
if (texture)
return texture;
if (!g_error_matches (internal_error, GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_UNSUPPORTED_CONTENT) &&
!g_error_matches (internal_error, GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_UNSUPPORTED_FORMAT))
{
g_propagate_error (error, internal_error);
return NULL;
}
g_clear_error (&internal_error);
return gdk_texture_new_from_bytes_pixbuf (bytes, error);
}
/**
* gdk_texture_new_from_filename:
* @path: (type filename): the filename to load
* @error: Return location for an error
*
* Creates a new texture by loading an image from a file.
*
* The file format is detected automatically. The supported formats
* are PNG and JPEG, though more formats might be available.
*
* If %NULL is returned, then @error will be set.
*
* Return value: A newly-created `GdkTexture`
*/
GdkTexture *
gdk_texture_new_from_filename (const char *path,
GError **error)
{
GdkTexture *texture;
GFile *file;
g_return_val_if_fail (path, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
file = g_file_new_for_path (path);
texture = gdk_texture_new_from_file (file, error);
g_object_unref (file);
return texture;
}
/**
* gdk_texture_get_width: (attributes org.gtk.Method.get_property=width)
* @texture: a `GdkTexture`
@@ -435,20 +695,6 @@ gdk_texture_download_surface (GdkTexture *texture)
return surface;
}
void
gdk_texture_download_area (GdkTexture *texture,
const GdkRectangle *area,
guchar *data,
gsize stride)
{
g_assert (area->x >= 0);
g_assert (area->y >= 0);
g_assert (area->x + area->width <= texture->width);
g_assert (area->y + area->height <= texture->height);
GDK_TEXTURE_GET_CLASS (texture)->download (texture, area, data, stride);
}
/**
* gdk_texture_download:
* @texture: a `GdkTexture`
@@ -485,10 +731,62 @@ gdk_texture_download (GdkTexture *texture,
g_return_if_fail (data != NULL);
g_return_if_fail (stride >= gdk_texture_get_width (texture) * 4);
gdk_texture_download_area (texture,
&(GdkRectangle) { 0, 0, texture->width, texture->height },
data,
stride);
GDK_TEXTURE_GET_CLASS (texture)->download (texture, data, stride);
}
/**
* gdk_texture_download_float:
* @texture: a `GdkTexture`
* @data: (array): pointer to enough memory to be filled with the
* downloaded data of @texture
* @stride: rowstride in elements, will usually be equal to
* gdk_texture_get_width() * 4
*
* Downloads the @texture into local memory in a high dynamic range format.
*
* This may be an expensive operation, as the actual texture data
* may reside on a GPU or on a remote display server and because the data
* may need to be upsampled if it was not already available in this
* format.
*
* You may want to use [method@Gdk.Texture.download] instead if you don't
* need high dynamic range support.
*
* The data format of the downloaded data is equivalent to
* GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED, so every downloaded
* pixel requires 16 bytes of memory.
*
* Note that the caller is responsible to provide sufficiently
* aligned memory to access the resulting data directly as floats.
*
* Since: 4.6
*/
void
gdk_texture_download_float (GdkTexture *texture,
float *data,
gsize stride)
{
g_return_if_fail (GDK_IS_TEXTURE (texture));
g_return_if_fail (data != NULL);
g_return_if_fail (stride >= gdk_texture_get_width (texture) * 4);
GDK_TEXTURE_GET_CLASS (texture)->download_float (texture, data, stride);
}
GdkTexture *
gdk_texture_download_texture (GdkTexture *texture)
{
g_return_val_if_fail (GDK_IS_TEXTURE (texture), NULL);
g_object_ref (texture);
while (!GDK_IS_MEMORY_TEXTURE (texture))
{
GdkTexture *downloaded = GDK_TEXTURE_GET_CLASS (texture)->download_texture (texture);
g_object_unref (texture);
texture = downloaded;
}
return texture;
}
gboolean
@@ -540,7 +838,8 @@ gdk_texture_get_render_data (GdkTexture *self,
* This is a utility function intended for debugging and testing.
* If you want more control over formats, proper error handling or
* want to store to a `GFile` or other location, you might want to
* look into using the gdk-pixbuf library.
* use [method@Gdk.Texture.save_to_png_bytes] or look into the
* gdk-pixbuf library.
*
* Returns: %TRUE if saving succeeded, %FALSE on failure.
*/
@@ -548,30 +847,110 @@ gboolean
gdk_texture_save_to_png (GdkTexture *texture,
const char *filename)
{
cairo_surface_t *surface;
cairo_status_t status;
GBytes *bytes;
gboolean result;
g_return_val_if_fail (GDK_IS_TEXTURE (texture), FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
gdk_texture_get_width (texture),
gdk_texture_get_height (texture));
gdk_texture_download (texture,
cairo_image_surface_get_data (surface),
cairo_image_surface_get_stride (surface));
cairo_surface_mark_dirty (surface);
status = cairo_surface_write_to_png (surface, filename);
if (status != CAIRO_STATUS_SUCCESS ||
cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
result = FALSE;
else
result = TRUE;
cairo_surface_destroy (surface);
bytes = gdk_save_png (texture);
result = g_file_set_contents (filename,
g_bytes_get_data (bytes, NULL),
g_bytes_get_size (bytes),
NULL);
g_bytes_unref (bytes);
return result;
}
/**
* gdk_texture_save_to_png_bytes:
* @texture: a `GdkTexture`
*
* Store the given @texture in memory as a PNG file.
* Use [ctor@Gdk.Texture.new_from_bytes] to read it back.
*
* If you want to serialize a texture, this is a convenient and
* portable way to do that.
*
* If you need more control over the generated image, such as
* attaching metadata, you should look into an image handling
* library such as the gdk-pixbuf library.
*
* If you are dealing with high dynamic range float data, you
* might also want to consider [method@Gdk.Texture.save_to_tiff_bytes]
* instead.
*
* Returns: a newly allocated `GBytes` containing PNG data
*
* Since: 4.6
*/
GBytes *
gdk_texture_save_to_png_bytes (GdkTexture *texture)
{
g_return_val_if_fail (GDK_IS_TEXTURE (texture), NULL);
return gdk_save_png (texture);
}
/**
* gdk_texture_save_to_tiff:
* @texture: a `GdkTexture`
* @filename: (type filename): the filename to store to
*
* Store the given @texture to the @filename as a TIFF file.
*
* GTK will attempt to store data without loss.
* Returns: %TRUE if saving succeeded, %FALSE on failure.
*
* Since: 4.6
*/
gboolean
gdk_texture_save_to_tiff (GdkTexture *texture,
const char *filename)
{
GBytes *bytes;
gboolean result;
g_return_val_if_fail (GDK_IS_TEXTURE (texture), FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
bytes = gdk_save_tiff (texture);
result = g_file_set_contents (filename,
g_bytes_get_data (bytes, NULL),
g_bytes_get_size (bytes),
NULL);
g_bytes_unref (bytes);
return result;
}
/**
* gdk_texture_save_to_tiff_bytes:
* @texture: a `GdkTexture`
*
* Store the given @texture in memory as a TIFF file.
*
* Use [ctor@Gdk.Texture.new_from_bytes] to read it back.
*
* This function is intended to store a representation of the
* texture's data that is as accurate as possible. This is
* particularly relevant when working with high dynamic range
* images and floating-point texture data.
*
* If that is not your concern and you are interested in a
* smaller size and a more portable format, you might want to
* use [method@Gdk.Texture.save_to_png_bytes].
*
* Returns: a newly allocated `GBytes` containing TIFF data
*
* Since: 4.6
*/
GBytes *
gdk_texture_save_to_tiff_bytes (GdkTexture *texture)
{
g_return_val_if_fail (GDK_IS_TEXTURE (texture), NULL);
return gdk_save_tiff (texture);
}

View File

@@ -38,6 +38,30 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkTexture, g_object_unref)
typedef struct _GdkTextureClass GdkTextureClass;
#define GDK_TEXTURE_ERROR (gdk_texture_error_quark ())
GDK_AVAILABLE_IN_4_6
GQuark gdk_texture_error_quark (void);
/**
* GdkTextureError:
* @GDK_TEXTURE_ERROR_TOO_LARGE: Not enough memory to handle this image
* @GDK_TEXTURE_ERROR_CORRUPT_IMAGE: The image data appears corrupted
* @GDK_TEXTURE_ERROR_UNSUPPORTED_CONTENT: The image contains features
* that cannot be loaded
* @GDK_TEXTURE_ERROR_UNSUPPORTED_FORMAT: The image format is not supported
*
* Possible errors that can be returned by `GdkTexture` constructors.
*
* Since: 4.6
*/
typedef enum
{
GDK_TEXTURE_ERROR_TOO_LARGE,
GDK_TEXTURE_ERROR_CORRUPT_IMAGE,
GDK_TEXTURE_ERROR_UNSUPPORTED_CONTENT,
GDK_TEXTURE_ERROR_UNSUPPORTED_FORMAT,
} GdkTextureError;
GDK_AVAILABLE_IN_ALL
GType gdk_texture_get_type (void) G_GNUC_CONST;
@@ -49,6 +73,12 @@ GdkTexture * gdk_texture_new_from_resource (const char
GDK_AVAILABLE_IN_ALL
GdkTexture * gdk_texture_new_from_file (GFile *file,
GError **error);
GDK_AVAILABLE_IN_4_6
GdkTexture * gdk_texture_new_from_filename (const char *path,
GError **error);
GDK_AVAILABLE_IN_4_6
GdkTexture * gdk_texture_new_from_bytes (GBytes *bytes,
GError **error);
GDK_AVAILABLE_IN_ALL
int gdk_texture_get_width (GdkTexture *texture) G_GNUC_PURE;
@@ -59,9 +89,20 @@ GDK_AVAILABLE_IN_ALL
void gdk_texture_download (GdkTexture *texture,
guchar *data,
gsize stride);
GDK_AVAILABLE_IN_4_6
void gdk_texture_download_float (GdkTexture *texture,
float *data,
gsize stride);
GDK_AVAILABLE_IN_ALL
gboolean gdk_texture_save_to_png (GdkTexture *texture,
const char *filename);
GDK_AVAILABLE_IN_4_6
GBytes * gdk_texture_save_to_png_bytes (GdkTexture *texture);
GDK_AVAILABLE_IN_4_6
gboolean gdk_texture_save_to_tiff (GdkTexture *texture,
const char *filename);
GDK_AVAILABLE_IN_4_6
GBytes * gdk_texture_save_to_tiff_bytes (GdkTexture *texture);
G_END_DECLS

View File

@@ -24,21 +24,23 @@ struct _GdkTexture
struct _GdkTextureClass {
GObjectClass parent_class;
/* mandatory: Download into a GdkMemoryTexture */
GdkTexture * (* download_texture) (GdkTexture *texture);
/* optional */
void (* download) (GdkTexture *texture,
const GdkRectangle *area,
guchar *data,
gsize stride);
void (* download_float) (GdkTexture *texture,
float *data,
gsize stride);
};
gpointer gdk_texture_new (const GdkTextureClass *klass,
int width,
int height);
gboolean gdk_texture_can_load (GBytes *bytes);
GdkTexture * gdk_texture_new_for_surface (cairo_surface_t *surface);
cairo_surface_t * gdk_texture_download_surface (GdkTexture *texture);
void gdk_texture_download_area (GdkTexture *texture,
const GdkRectangle *area,
guchar *data,
gsize stride);
/* NB: GdkMemoryTexture */
GdkTexture * gdk_texture_download_texture (GdkTexture *texture);
gboolean gdk_texture_set_render_data (GdkTexture *self,
gpointer key,

View File

@@ -78,6 +78,13 @@ gdk_toplevel_default_show_window_menu (GdkToplevel *toplevel,
return FALSE;
}
static gboolean
gdk_toplevel_default_titlebar_gesture (GdkToplevel *toplevel,
GdkTitlebarGesture gesture)
{
return FALSE;
}
static gboolean
gdk_toplevel_default_supports_edge_constraints (GdkToplevel *toplevel)
{
@@ -114,6 +121,7 @@ gdk_toplevel_default_init (GdkToplevelInterface *iface)
iface->supports_edge_constraints = gdk_toplevel_default_supports_edge_constraints;
iface->inhibit_system_shortcuts = gdk_toplevel_default_inhibit_system_shortcuts;
iface->restore_system_shortcuts = gdk_toplevel_default_restore_system_shortcuts;
iface->titlebar_gesture = gdk_toplevel_default_titlebar_gesture;
/**
* GdkToplevel:state: (attributes org.gtk.Property.get=gdk_toplevel_get_state)
@@ -716,3 +724,13 @@ gdk_toplevel_begin_move (GdkToplevel *toplevel,
x, y,
timestamp);
}
gboolean
gdk_toplevel_titlebar_gesture (GdkToplevel *toplevel,
GdkTitlebarGesture gesture)
{
g_return_val_if_fail (GDK_IS_TOPLEVEL (toplevel), FALSE);
return GDK_TOPLEVEL_GET_IFACE (toplevel)->titlebar_gesture (toplevel,
gesture);
}

View File

@@ -115,6 +115,13 @@ typedef enum
GDK_TOPLEVEL_STATE_LEFT_RESIZABLE = 1 << 15
} GdkToplevelState;
typedef enum
{
GDK_TITLEBAR_GESTURE_DOUBLE_CLICK = 1,
GDK_TITLEBAR_GESTURE_RIGHT_CLICK = 2,
GDK_TITLEBAR_GESTURE_MIDDLE_CLICK = 3
} GdkTitlebarGesture;
#define GDK_TYPE_TOPLEVEL (gdk_toplevel_get_type ())
@@ -196,6 +203,10 @@ void gdk_toplevel_begin_move (GdkToplevel *toplevel,
double y,
guint32 timestamp);
GDK_AVAILABLE_IN_4_4
gboolean gdk_toplevel_titlebar_gesture (GdkToplevel *toplevel,
GdkTitlebarGesture gesture);
G_END_DECLS
#endif /* __GDK_TOPLEVEL_H__ */

View File

@@ -38,6 +38,8 @@ struct _GdkToplevelInterface
double x,
double y,
guint32 timestamp);
gboolean (* titlebar_gesture) (GdkToplevel *toplevel,
GdkTitlebarGesture gesture);
};
typedef enum

View File

@@ -94,6 +94,14 @@
*/
#define GDK_VERSION_4_4 (G_ENCODE_VERSION (4, 4))
/**
* GDK_VERSION_4_6:
*
* A macro that evaluates to the 4.6 version of GDK, in a format
* that can be used by the C pre-processor.
*/
#define GDK_VERSION_4_6 (G_ENCODE_VERSION (4, 6))
/* evaluates to the current stable version; for development cycles,
* this means the next stable target, with a hard backstop to the
@@ -221,4 +229,18 @@
# define GDK_DEPRECATED_IN_4_4_FOR(f) _GDK_EXTERN
#endif
#if GDK_VERSION_MAX_ALLOWED < GDK_VERSION_4_6
# define GDK_AVAILABLE_IN_4_6 GDK_UNAVAILABLE(4, 6)
#else
# define GDK_AVAILABLE_IN_4_6 _GDK_EXTERN
#endif
#if GDK_VERSION_MIN_REQUIRED >= GDK_VERSION_4_6
# define GDK_DEPRECATED_IN_4_6 GDK_DEPRECATED
# define GDK_DEPRECATED_IN_4_6_FOR(f) GDK_DEPRECATED_FOR(f)
#else
# define GDK_DEPRECATED_IN_4_6 _GDK_EXTERN
# define GDK_DEPRECATED_IN_4_6_FOR(f) _GDK_EXTERN
#endif
#endif /* __GDK_VERSION_MACROS_H__ */

View File

@@ -117,104 +117,104 @@ gdk_vulkan_strerror (VkResult result)
switch (result)
{
case VK_SUCCESS:
return "Command successfully completed.";
return "Command successfully completed. (VK_SUCCESS)";
case VK_NOT_READY:
return "A fence or query has not yet completed.";
return "A fence or query has not yet completed. (VK_NOT_READY)";
case VK_TIMEOUT:
return "A wait operation has not completed in the specified time.";
return "A wait operation has not completed in the specified time. (VK_TIMEOUT)";
case VK_EVENT_SET:
return "An event is signaled.";
return "An event is signaled. (VK_EVENT_SET)";
case VK_EVENT_RESET:
return "An event is unsignaled.";
return "An event is unsignaled. (VK_EVENT_RESET)";
case VK_INCOMPLETE:
return "A return array was too small for the result.";
return "A return array was too small for the result. (VK_INCOMPLETE)";
case VK_SUBOPTIMAL_KHR:
return "A swapchain no longer matches the surface properties exactly, but can still be used to present to the surface successfully.";
return "A swapchain no longer matches the surface properties exactly, but can still be used to present to the surface successfully. (VK_SUBOPTIMAL_KHR)";
case VK_ERROR_OUT_OF_HOST_MEMORY:
return "A host memory allocation has failed.";
return "A host memory allocation has failed. (VK_ERROR_OUT_OF_HOST_MEMORY)";
case VK_ERROR_OUT_OF_DEVICE_MEMORY:
return "A device memory allocation has failed.";
return "A device memory allocation has failed. (VK_ERROR_OUT_OF_DEVICE_MEMORY)";
case VK_ERROR_INITIALIZATION_FAILED:
return "Initialization of an object could not be completed for implementation-specific reasons.";
return "Initialization of an object could not be completed for implementation-specific reasons. (VK_ERROR_INITIALIZATION_FAILED)";
case VK_ERROR_DEVICE_LOST:
return "The logical or physical device has been lost.";
return "The logical or physical device has been lost. (VK_ERROR_DEVICE_LOST)";
case VK_ERROR_MEMORY_MAP_FAILED:
return "Mapping of a memory object has failed.";
return "Mapping of a memory object has failed. (VK_ERROR_MEMORY_MAP_FAILED)";
case VK_ERROR_LAYER_NOT_PRESENT:
return "A requested layer is not present or could not be loaded.";
return "A requested layer is not present or could not be loaded. (VK_ERROR_LAYER_NOT_PRESENT)";
case VK_ERROR_EXTENSION_NOT_PRESENT:
return "A requested extension is not supported.";
return "A requested extension is not supported. (VK_ERROR_EXTENSION_NOT_PRESENT)";
case VK_ERROR_FEATURE_NOT_PRESENT:
return "A requested feature is not supported.";
return "A requested feature is not supported. (VK_ERROR_FEATURE_NOT_PRESENT)";
case VK_ERROR_INCOMPATIBLE_DRIVER:
return "The requested version of Vulkan is not supported by the driver or is otherwise incompatible for implementation-specific reasons.";
return "The requested version of Vulkan is not supported by the driver or is otherwise incompatible for implementation-specific reasons. (VK_ERROR_INCOMPATIBLE_DRIVER)";
case VK_ERROR_TOO_MANY_OBJECTS:
return "Too many objects of the type have already been created.";
return "Too many objects of the type have already been created. (VK_ERROR_TOO_MANY_OBJECTS)";
case VK_ERROR_FORMAT_NOT_SUPPORTED:
return "A requested format is not supported on this device.";
return "A requested format is not supported on this device. (VK_ERROR_FORMAT_NOT_SUPPORTED)";
#if VK_HEADER_VERSION >= 24
case VK_ERROR_FRAGMENTED_POOL:
return "A requested pool allocation has failed due to fragmentation of the pools memory.";
return "A requested pool allocation has failed due to fragmentation of the pools memory. (VK_ERROR_FRAGMENTED_POOL)";
#endif
case VK_ERROR_SURFACE_LOST_KHR:
return "A surface is no longer available.";
return "A surface is no longer available. (VK_ERROR_SURFACE_LOST_KHR)";
case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR:
return "The requested window is already in use by Vulkan or another API in a manner which prevents it from being used again.";
return "The requested window is already in use by Vulkan or another API in a manner which prevents it from being used again. (VK_ERROR_NATIVE_WINDOW_IN_USE_KHR)";
case VK_ERROR_OUT_OF_DATE_KHR:
return "A surface has changed in such a way that it is no longer compatible with the swapchain.";
return "A surface has changed in such a way that it is no longer compatible with the swapchain. (VK_ERROR_OUT_OF_DATE_KHR)";
case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR:
return "The display used by a swapchain does not use the same presentable image layout, or is incompatible in a way that prevents sharing an image.";
return "The display used by a swapchain does not use the same presentable image layout, or is incompatible in a way that prevents sharing an image. (VK_ERROR_INCOMPATIBLE_DISPLAY_KHR)";
case VK_ERROR_VALIDATION_FAILED_EXT:
return "The application caused the validation layer to fail.";
return "The application caused the validation layer to fail. (VK_ERROR_VALIDATION_FAILED_EXT)";
case VK_ERROR_INVALID_SHADER_NV:
return "One or more shaders failed to compile or link.";
return "One or more shaders failed to compile or link. (VK_ERROR_INVALID_SHADER_NV)";
#if VK_HEADER_VERSION >= 39
case VK_ERROR_OUT_OF_POOL_MEMORY_KHR:
return "A pool memory allocation has failed.";
return "A pool memory allocation has failed. (VK_ERROR_OUT_OF_POOL_MEMORY_KHR)";
#endif
#if VK_HEADER_VERSION >= 54
case VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR:
return "An external handle is not a valid handle of the specified type.";
return "An external handle is not a valid handle of the specified type. (VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR)";
#endif
#if VK_HEADER_VERSION >= 64
case VK_ERROR_NOT_PERMITTED_EXT:
return "The caller does not have sufficient privileges.";
return "The caller does not have sufficient privileges. (VK_ERROR_NOT_PERMITTED_EXT)";
#endif
#if VK_HEADER_VERSION >= 72
case VK_ERROR_FRAGMENTATION_EXT:
return "A descriptor pool creation has failed due to fragmentation";
return "A descriptor pool creation has failed due to fragmentation. (VK_ERROR_FRAGMENTATION_EXT)";
#endif
#if VK_HEADER_VERSION >= 89
case VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT:
return "Invalid DRM format modifier plane layout";
return "Invalid DRM format modifier plane layout (VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT)";
#endif
#if VK_HEADER_VERSION >= 97
case VK_ERROR_INVALID_DEVICE_ADDRESS_EXT:
return "Invalid device address";
return "Invalid device address (VK_ERROR_INVALID_DEVICE_ADDRESS_EXT)";
#endif
#if VK_HEADER_VERSION >= 105
case VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT:
return "An operation on a swapchain created with VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT failed as it did not have exclusive full-screen access.";
return "An operation on a swapchain created with VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT failed as it did not have exclusive full-screen access. (VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT)";
#endif
#if VK_HEADER_VERSION >= 131
case VK_ERROR_UNKNOWN:
return "An unknown error has occurred; either the application has provided invalid input, or an implementation failure has occurred.";
return "An unknown error has occurred; either the application has provided invalid input, or an implementation failure has occurred. (VK_ERROR_UNKNOWN)";
#endif
#if VK_HEADER_VERSION >= 135
#if VK_HEADER_VERSION < 162
case VK_ERROR_INCOMPATIBLE_VERSION_KHR:
return "This error was removed by the Vulkan gods.";
return "This error was removed by the Vulkan gods. (VK_ERROR_INCOMPATIBLE_VERSION_KHR)";
#endif
case VK_THREAD_IDLE_KHR:
return "A deferred operation is not complete but there is currently no work for this thread to do at the time of this call.";
return "A deferred operation is not complete but there is currently no work for this thread to do at the time of this call. (VK_THREAD_IDLE_KHR)";
case VK_THREAD_DONE_KHR:
return "A deferred operation is not complete but there is no work remaining to assign to additional threads.";
return "A deferred operation is not complete but there is no work remaining to assign to additional threads. (VK_THREAD_DONE_KHR)";
case VK_OPERATION_DEFERRED_KHR:
return "A deferred operation was requested and at least some of the work was deferred.";
return "A deferred operation was requested and at least some of the work was deferred. (VK_OPERATION_DEFERRED_KHR)";
case VK_OPERATION_NOT_DEFERRED_KHR:
return "A deferred operation was requested and no operations were deferred.";
return "A deferred operation was requested and no operations were deferred. (VK_OPERATION_NOT_DEFERRED_KHR)";
case VK_ERROR_PIPELINE_COMPILE_REQUIRED_EXT:
return "A requested pipeline creation would have required compilation, but the application requested compilation to not be performed.";
return "A requested pipeline creation would have required compilation, but the application requested compilation to not be performed. (VK_ERROR_PIPELINE_COMPILE_REQUIRED_EXT)";
#endif
#if VK_HEADER_VERSION < 140
case VK_RESULT_RANGE_SIZE:

334
gdk/loaders/gdkjpeg.c Normal file
View File

@@ -0,0 +1,334 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 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 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 "gdkjpegprivate.h"
#include "gdkintl.h"
#include "gdktexture.h"
#include "gdkmemorytextureprivate.h"
#include "gdkprofilerprivate.h"
#include <jpeglib.h>
#include <jerror.h>
#include <setjmp.h>
/* {{{ Error handling */
/* No sigsetjmp on Windows */
#ifndef HAVE_SIGSETJMP
#define sigjmp_buf jmp_buf
#define sigsetjmp(jb, x) setjmp(jb)
#define siglongjmp longjmp
#endif
struct error_handler_data {
struct jpeg_error_mgr pub;
sigjmp_buf setjmp_buffer;
GError **error;
};
static void
fatal_error_handler (j_common_ptr cinfo)
{
struct error_handler_data *errmgr;
char buffer[JMSG_LENGTH_MAX];
errmgr = (struct error_handler_data *) cinfo->err;
cinfo->err->format_message (cinfo, buffer);
if (errmgr->error && *errmgr->error == NULL)
g_set_error (errmgr->error,
GDK_TEXTURE_ERROR,
GDK_TEXTURE_ERROR_CORRUPT_IMAGE,
_("Error interpreting JPEG image file (%s)"), buffer);
siglongjmp (errmgr->setjmp_buffer, 1);
g_assert_not_reached ();
}
static void
output_message_handler (j_common_ptr cinfo)
{
/* do nothing */
}
/* }}} */
/* {{{ Format conversion */
static void
convert_rgba_to_rgb (guchar *data,
int width,
int height,
int stride)
{
gsize x, y;
guchar *src, *dest;
for (y = 0; y < height; y++)
{
src = data;
dest = data;
for (x = 0; x < width; x++)
{
guint32 pixel;
memcpy (&pixel, src, sizeof (guint32));
dest[0] = (pixel & 0x00ff0000) >> 16;
dest[1] = (pixel & 0x0000ff00) >> 8;
dest[2] = (pixel & 0x000000ff) >> 0;
dest += 3;
src += 4;
}
data += stride;
}
}
static void
convert_grayscale_to_rgb (guchar *data,
int width,
int height,
int stride)
{
gsize x, y;
guchar *dest, *src;
for (y = 0; y < height; y++)
{
src = data + width;
dest = data + 3 * width;
for (x = 0; x < width; x++)
{
dest -= 3;
src -= 1;
dest[0] = *src;
dest[1] = *src;
dest[2] = *src;
}
data += stride;
}
}
static void
convert_cmyk_to_rgba (guchar *data,
int width,
int height,
int stride)
{
gsize x, r;
guchar *dest;
for (r = 0; r < height; r++)
{
dest = data;
for (x = 0; x < width; x++)
{
int c, m, y, k;
c = dest[0];
m = dest[1];
y = dest[2];
k = dest[3];
dest[0] = k * c / 255;
dest[1] = k * m / 255;
dest[2] = k * y / 255;
dest[3] = 255;
dest += 4;
}
data += stride;
}
}
/* }}} */
/* {{{ Public API */
GdkTexture *
gdk_load_jpeg (GBytes *input_bytes,
GError **error)
{
struct jpeg_decompress_struct info;
struct error_handler_data jerr;
guint width, height, stride;
unsigned char *data;
unsigned char *row[1];
GBytes *bytes;
GdkTexture *texture;
GdkMemoryFormat format;
G_GNUC_UNUSED guint64 before = GDK_PROFILER_CURRENT_TIME;
info.err = jpeg_std_error (&jerr.pub);
jerr.pub.error_exit = fatal_error_handler;
jerr.pub.output_message = output_message_handler;
jerr.error = error;
if (sigsetjmp (jerr.setjmp_buffer, 1))
{
jpeg_destroy_decompress (&info);
return NULL;
}
jpeg_create_decompress (&info);
jpeg_mem_src (&info,
g_bytes_get_data (input_bytes, NULL),
g_bytes_get_size (input_bytes));
jpeg_read_header (&info, TRUE);
jpeg_start_decompress (&info);
width = info.output_width;
height = info.output_height;
switch ((int)info.out_color_space)
{
case JCS_GRAYSCALE:
case JCS_RGB:
stride = 3 * width;
data = g_try_malloc_n (stride, height);
format = GDK_MEMORY_R8G8B8;
break;
case JCS_CMYK:
stride = 4 * width;
data = g_try_malloc_n (stride, height);
format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
break;
default:
g_set_error (error,
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_UNSUPPORTED_CONTENT,
_("Unsupported JPEG colorspace (%d)"), info.out_color_space);
jpeg_destroy_decompress (&info);
return NULL;
}
if (!data)
{
g_set_error (error,
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_TOO_LARGE,
_("Not enough memory for image size %ux%u"), width, height);
jpeg_destroy_decompress (&info);
return NULL;
}
while (info.output_scanline < info.output_height)
{
row[0] = (unsigned char *)(&data[stride * info.output_scanline]);
jpeg_read_scanlines (&info, row, 1);
}
switch ((int)info.out_color_space)
{
case JCS_GRAYSCALE:
convert_grayscale_to_rgb (data, width, height, stride);
format = GDK_MEMORY_R8G8B8;
break;
case JCS_RGB:
break;
case JCS_CMYK:
convert_cmyk_to_rgba (data, width, height, stride);
break;
default:
g_assert_not_reached ();
}
jpeg_finish_decompress (&info);
jpeg_destroy_decompress (&info);
bytes = g_bytes_new_take (data, stride * height);
texture = gdk_memory_texture_new (width, height,
format,
bytes, stride);
g_bytes_unref (bytes);
gdk_profiler_end_mark (before, "jpeg load", NULL);
return texture;
}
GBytes *
gdk_save_jpeg (GdkTexture *texture)
{
struct jpeg_compress_struct info;
struct error_handler_data jerr;
struct jpeg_error_mgr err;
guchar *data = NULL;
gulong size = 0;
guchar *input = NULL;
guchar *row;
int width, height, stride;
width = gdk_texture_get_width (texture);
height = gdk_texture_get_height (texture);
info.err = jpeg_std_error (&jerr.pub);
jerr.pub.error_exit = fatal_error_handler;
jerr.pub.output_message = output_message_handler;
jerr.error = NULL;
if (sigsetjmp (jerr.setjmp_buffer, 1))
{
free (data);
g_free (input);
jpeg_destroy_compress (&info);
return NULL;
}
info.err = jpeg_std_error (&err);
jpeg_create_compress (&info);
info.image_width = width;
info.image_height = height;
info.input_components = 3;
info.in_color_space = JCS_RGB;
jpeg_set_defaults (&info);
jpeg_set_quality (&info, 75, TRUE);
jpeg_mem_dest (&info, &data, &size);
stride = width * 4;
input = g_malloc (stride * height);
gdk_texture_download (texture, input, stride);
convert_rgba_to_rgb (data, width, height, stride);
jpeg_start_compress (&info, TRUE);
while (info.next_scanline < info.image_height)
{
row = &input[info.next_scanline * stride];
jpeg_write_scanlines (&info, &row, 1);
}
jpeg_finish_compress (&info);
g_free (input);
jpeg_destroy_compress (&info);
return g_bytes_new_with_free_func (data, size, (GDestroyNotify) free, NULL);
}
/* }}} */
/* vim:set foldmethod=marker expandtab: */

View File

@@ -0,0 +1,43 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 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 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 __GDK_JPEG_PRIVATE_H__
#define __GDK_JPEG_PRIVATE_H__
#include "gdkmemorytexture.h"
#include <gio/gio.h>
#define JPEG_SIGNATURE "\xff\xd8"
GdkTexture *gdk_load_jpeg (GBytes *bytes,
GError **error);
GBytes *gdk_save_jpeg (GdkTexture *texture);
static inline gboolean
gdk_is_jpeg (GBytes *bytes)
{
const char *data;
gsize size;
data = g_bytes_get_data (bytes, &size);
return size > strlen (JPEG_SIGNATURE) &&
memcmp (data, JPEG_SIGNATURE, strlen (JPEG_SIGNATURE)) == 0;
}
#endif

577
gdk/loaders/gdkpng.c Normal file
View File

@@ -0,0 +1,577 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 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 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 "gdkpngprivate.h"
#include "gdkintl.h"
#include "gdkmemorytextureprivate.h"
#include "gdkprofilerprivate.h"
#include "gdktexture.h"
#include "gdktextureprivate.h"
#include "gsk/ngl/fp16private.h"
#include <png.h>
#include <stdio.h>
/* The main difference between the png load/save code here and
* gdk-pixbuf is that we can support loading 16-bit data in the
* future, and we can extract gamma and colorspace information
* to produce linear, color-corrected data.
*/
/* {{{ Callbacks */
/* No sigsetjmp on Windows */
#ifndef HAVE_SIGSETJMP
#define sigjmp_buf jmp_buf
#define sigsetjmp(jb, x) setjmp(jb)
#define siglongjmp longjmp
#endif
typedef struct
{
guchar *data;
gsize size;
gsize position;
} png_io;
static void
png_read_func (png_structp png,
png_bytep data,
png_size_t size)
{
png_io *io;
io = png_get_io_ptr (png);
if (io->position + size > io->size)
png_error (png, "Read past EOF");
memcpy (data, io->data + io->position, size);
io->position += size;
}
static void
png_write_func (png_structp png,
png_bytep data,
png_size_t size)
{
png_io *io;
io = png_get_io_ptr (png);
if (io->position > io->size ||
io->size - io->position < size)
{
io->size = io->position + size;
io->data = g_realloc (io->data, io->size);
}
memcpy (io->data + io->position, data, size);
io->position += size;
}
static void
png_flush_func (png_structp png)
{
}
static png_voidp
png_malloc_callback (png_structp o,
png_size_t size)
{
return g_try_malloc (size);
}
static void
png_free_callback (png_structp o,
png_voidp x)
{
g_free (x);
}
static void
png_simple_error_callback (png_structp png,
png_const_charp error_msg)
{
GError **error = png_get_error_ptr (png);
if (error && !*error)
g_set_error (error,
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_CORRUPT_IMAGE,
_("Error reading png (%s)"), error_msg);
longjmp (png_jmpbuf (png), 1);
}
static void
png_simple_warning_callback (png_structp png,
png_const_charp error_msg)
{
}
/* }}} */
/* {{{ Format conversion */
static void
unpremultiply (guchar *data,
int width,
int height)
{
gsize x, y;
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
{
guchar *b = &data[x * 4];
guint32 pixel;
guchar alpha;
memcpy (&pixel, b, sizeof (guint32));
alpha = (pixel & 0xff000000) >> 24;
if (alpha == 0)
{
b[0] = 0;
b[1] = 0;
b[2] = 0;
b[3] = 0;
}
else
{
b[0] = (((pixel & 0x00ff0000) >> 16) * 255 + alpha / 2) / alpha;
b[1] = (((pixel & 0x0000ff00) >> 8) * 255 + alpha / 2) / alpha;
b[2] = (((pixel & 0x000000ff) >> 0) * 255 + alpha / 2) / alpha;
b[3] = alpha;
}
}
data += width * 4;
}
}
static void
unpremultiply_float_to_16bit (guchar *data,
int width,
int height)
{
gsize x, y;
float *src = (float *)data;;
guint16 *dest = (guint16 *)data;
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
{
float r, g, b, a;
r = src[0];
g = src[1];
b = src[2];
a = src[3];
if (a == 0)
{
dest[0] = 0;
dest[1] = 0;
dest[2] = 0;
dest[3] = 0;
}
else
{
dest[0] = (guint16) CLAMP (65536.f * r / a, 0.f, 65535.f);
dest[1] = (guint16) CLAMP (65536.f * g / a, 0.f, 65535.f);
dest[2] = (guint16) CLAMP (65536.f * b / a, 0.f, 65535.f);
dest[3] = (guint16) CLAMP (65536.f * a, 0.f, 65535.f);
}
dest += 4;
src += 4;
}
}
}
static inline int
multiply_alpha (int alpha, int color)
{
int temp = (alpha * color) + 0x80;
return ((temp + (temp >> 8)) >> 8);
}
static void
premultiply_data (png_structp png,
png_row_infop row_info,
png_bytep data)
{
unsigned int i;
for (i = 0; i < row_info->rowbytes; i += 4)
{
uint8_t *base = &data[i];
uint8_t alpha = base[3];
uint32_t p;
if (alpha == 0)
{
p = 0;
}
else
{
uint8_t red = base[0];
uint8_t green = base[1];
uint8_t blue = base[2];
if (alpha != 0xff)
{
red = multiply_alpha (alpha, red);
green = multiply_alpha (alpha, green);
blue = multiply_alpha (alpha, blue);
}
p = ((uint32_t)alpha << 24) | (red << 16) | (green << 8) | (blue << 0);
}
memcpy (base, &p, sizeof (uint32_t));
}
}
static void
convert_bytes_to_data (png_structp png,
png_row_infop row_info,
png_bytep data)
{
unsigned int i;
for (i = 0; i < row_info->rowbytes; i += 4)
{
uint8_t *base = &data[i];
uint8_t red = base[0];
uint8_t green = base[1];
uint8_t blue = base[2];
uint32_t pixel;
pixel = (0xffu << 24) | (red << 16) | (green << 8) | (blue << 0);
memcpy (base, &pixel, sizeof (uint32_t));
}
}
static void
premultiply_16bit (guchar *data,
int width,
int height,
int stride)
{
gsize x, y;
guint16 *src;
for (y = 0; y < height; y++)
{
src = (guint16 *)data;
for (x = 0; x < width; x++)
{
float alpha = src[x * 4 + 3] / 65535.f;
src[x * 4 ] = (guint16) CLAMP (src[x * 4 ] * alpha, 0.f, 65535.f);
src[x * 4 + 1] = (guint16) CLAMP (src[x * 4 + 1] * alpha, 0.f, 65535.f);
src[x * 4 + 2] = (guint16) CLAMP (src[x * 4 + 2] * alpha, 0.f, 65535.f);
}
data += stride;
}
}
/* }}} */
/* {{{ Public API */
GdkTexture *
gdk_load_png (GBytes *bytes,
GError **error)
{
png_io io;
png_struct *png = NULL;
png_info *info;
guint width, height;
int depth, color_type;
int interlace, stride;
GdkMemoryFormat format;
guchar *buffer = NULL;
guchar **row_pointers = NULL;
GBytes *out_bytes;
GdkTexture *texture;
int bpp;
G_GNUC_UNUSED gint64 before = GDK_PROFILER_CURRENT_TIME;
io.data = (guchar *)g_bytes_get_data (bytes, &io.size);
io.position = 0;
png = png_create_read_struct_2 (PNG_LIBPNG_VER_STRING,
error,
png_simple_error_callback,
png_simple_warning_callback,
NULL,
png_malloc_callback,
png_free_callback);
if (png == NULL)
g_error ("Out of memory");
info = png_create_info_struct (png);
if (info == NULL)
g_error ("Out of memory");
png_set_read_fn (png, &io, png_read_func);
if (sigsetjmp (png_jmpbuf (png), 1))
{
g_free (buffer);
g_free (row_pointers);
png_destroy_read_struct (&png, &info, NULL);
return NULL;
}
png_read_info (png, info);
png_get_IHDR (png, info,
&width, &height, &depth,
&color_type, &interlace, NULL, NULL);
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb (png);
if (color_type == PNG_COLOR_TYPE_GRAY)
png_set_expand_gray_1_2_4_to_8 (png);
if (png_get_valid (png, info, PNG_INFO_tRNS))
png_set_tRNS_to_alpha (png);
if (depth == 8)
png_set_filler (png, 0xff, PNG_FILLER_AFTER);
if (depth < 8)
png_set_packing (png);
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb (png);
if (interlace != PNG_INTERLACE_NONE)
png_set_interlace_handling (png);
png_read_update_info (png, info);
png_get_IHDR (png, info,
&width, &height, &depth,
&color_type, &interlace, NULL, NULL);
if ((depth != 8 && depth != 16) ||
!(color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA))
{
png_destroy_read_struct (&png, &info, NULL);
g_set_error (error,
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_UNSUPPORTED_CONTENT,
_("Failed to parse png image"));
return NULL;
}
switch (color_type)
{
case PNG_COLOR_TYPE_RGB_ALPHA:
if (depth == 8)
{
format = GDK_MEMORY_DEFAULT;
png_set_read_user_transform_fn (png, premultiply_data);
}
else
{
format = GDK_MEMORY_R16G16B16A16_PREMULTIPLIED;
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
png_set_swap (png);
#endif
}
break;
case PNG_COLOR_TYPE_RGB:
if (depth == 8)
{
format = GDK_MEMORY_DEFAULT;
png_set_read_user_transform_fn (png, convert_bytes_to_data);
}
else
{
format = GDK_MEMORY_R16G16B16;
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
png_set_swap (png);
#endif
}
break;
default:
g_assert_not_reached ();
}
bpp = gdk_memory_format_bytes_per_pixel (format);
stride = width * bpp;
if (stride % 8)
stride += 8 - stride % 8;
buffer = g_try_malloc_n (height, stride);
row_pointers = g_try_malloc_n (height, sizeof (char *));
if (!buffer || !row_pointers)
{
g_free (buffer);
g_free (row_pointers);
png_destroy_read_struct (&png, &info, NULL);
g_set_error (error,
GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_TOO_LARGE,
_("Not enough memory for image size %ux%u"), width, height);
return NULL;
}
for (int i = 0; i < height; i++)
row_pointers[i] = &buffer[i * stride];
png_read_image (png, row_pointers);
png_read_end (png, info);
if (format == GDK_MEMORY_R16G16B16A16_PREMULTIPLIED)
premultiply_16bit (buffer, width, height, stride);
out_bytes = g_bytes_new_take (buffer, height * stride);
texture = gdk_memory_texture_new (width, height, format, out_bytes, stride);
g_bytes_unref (out_bytes);
g_free (row_pointers);
png_destroy_read_struct (&png, &info, NULL);
if (GDK_PROFILER_IS_RUNNING)
{
gint64 end = GDK_PROFILER_CURRENT_TIME;
if (end - before > 500000)
gdk_profiler_add_mark (before, end - before, "png load", NULL);
}
return texture;
}
GBytes *
gdk_save_png (GdkTexture *texture)
{
png_struct *png = NULL;
png_info *info;
png_io io = { NULL, 0, 0 };
guint width, height, stride;
guchar *data = NULL;
guchar *row;
int y;
GdkTexture *mtexture;
GdkMemoryFormat format;
int png_format;
int depth;
width = gdk_texture_get_width (texture);
height = gdk_texture_get_height (texture);
mtexture = gdk_texture_download_texture (texture);
format = gdk_memory_texture_get_format (GDK_MEMORY_TEXTURE (mtexture));
switch (format)
{
case GDK_MEMORY_B8G8R8A8_PREMULTIPLIED:
case GDK_MEMORY_A8R8G8B8_PREMULTIPLIED:
case GDK_MEMORY_R8G8B8A8_PREMULTIPLIED:
case GDK_MEMORY_B8G8R8A8:
case GDK_MEMORY_A8R8G8B8:
case GDK_MEMORY_R8G8B8A8:
case GDK_MEMORY_A8B8G8R8:
case GDK_MEMORY_R8G8B8:
case GDK_MEMORY_B8G8R8:
stride = width * 4;
data = g_malloc_n (stride, height);
gdk_texture_download (mtexture, data, stride);
unpremultiply (data, width, height);
png_format = PNG_COLOR_TYPE_RGB_ALPHA;
depth = 8;
break;
case GDK_MEMORY_R16G16B16:
case GDK_MEMORY_R16G16B16A16_PREMULTIPLIED:
case GDK_MEMORY_R16G16B16_FLOAT:
case GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED:
case GDK_MEMORY_R32G32B32_FLOAT:
case GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED:
data = g_malloc_n (width * 16, height);
gdk_texture_download_float (mtexture, (float *)data, width * 4);
unpremultiply_float_to_16bit (data, width, height);
png_format = PNG_COLOR_TYPE_RGB_ALPHA;
stride = width * 8;
depth = 16;
break;
case GDK_MEMORY_N_FORMATS:
default:
g_assert_not_reached ();
}
png = png_create_write_struct_2 (PNG_LIBPNG_VER_STRING, NULL,
png_simple_error_callback,
png_simple_warning_callback,
NULL,
png_malloc_callback,
png_free_callback);
if (!png)
return NULL;
info = png_create_info_struct (png);
if (!info)
{
png_destroy_read_struct (&png, NULL, NULL);
return NULL;
}
if (sigsetjmp (png_jmpbuf (png), 1))
{
g_free (data);
g_free (io.data);
png_destroy_read_struct (&png, &info, NULL);
return NULL;
}
png_set_write_fn (png, &io, png_write_func, png_flush_func);
png_set_IHDR (png, info, width, height, depth,
png_format,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
png_write_info (png, info);
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
png_set_swap (png);
#endif
for (y = 0, row = data; y < height; y++, row += stride)
png_write_rows (png, &row, 1);
png_write_end (png, info);
png_destroy_write_struct (&png, &info);
g_free (data);
return g_bytes_new_take (io.data, io.size);
}
/* }}} */
/* vim:set foldmethod=marker expandtab: */

View File

@@ -0,0 +1,43 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 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 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 __GDK_PNG_PRIVATE_H__
#define __GDK_PNG_PRIVATE_H__
#include "gdktexture.h"
#include <gio/gio.h>
#define PNG_SIGNATURE "\x89PNG"
GdkTexture *gdk_load_png (GBytes *bytes,
GError **error);
GBytes *gdk_save_png (GdkTexture *texture);
static inline gboolean
gdk_is_png (GBytes *bytes)
{
const char *data;
gsize size;
data = g_bytes_get_data (bytes, &size);
return size > strlen (PNG_SIGNATURE) &&
memcmp (data, PNG_SIGNATURE, strlen (PNG_SIGNATURE)) == 0;
}
#endif

Some files were not shown because too many files have changed in this diff Show More