Gtk.jl icon indicating copy to clipboard operation
Gtk.jl copied to clipboard

Linux mouse cursors no longer "loaded" since Gtk.jl v1.0.0.

Open ma-laforge opened this issue 4 years ago • 2 comments

I realize (think?) there is no current support for mouse cursors in Gtk.jl, but:

In Gtk v0.18.0, I could use the GTK C calls to change mouse cursors in my ubuntu session.

However, since Gtk v1.0.0, this is no longer possible:

  • The GTK API calls work, but the mouse cursor pretty much stays as an arrow.
  • Some cursors change, but they are really ugly compared to what GTK usually supports.

GTK (GDK) Cursors:

--> https://developer.gnome.org/gdk3/stable/gdk3-Cursors.html#gdk-cursor-new-from-name

Some examples: Cursors_example

Comment

Everything seems fine in Windows 10 using Julia v1.5 & Gtk.jl v1.1.4.

Environment

I am using Ubuntu 18.04 with Julia v1.3.1.

ma-laforge avatar Jul 27 '20 16:07 ma-laforge

Test application

You should be able to reproduce the problem with the following test application.

Simply click on the window canvas to cycle through the different cursors in the list.

using Gtk
using Gtk.ShortNames

global listindex = 0

function gdk_cursor_new(id::String)
	d = ccall((:gdk_display_get_default,Gtk.libgdk),Ptr{Nothing},(Cstring,),id)
	return ccall((:gdk_cursor_new_from_name,Gtk.libgdk),Ptr{Nothing},(Ptr{Nothing}, Cstring), d,id)
end

function gdk_window_set_cursor(wnd, cursor::Ptr{Nothing})
	wptr = Gtk.GAccessor.window(wnd)
	ccall((:gdk_window_set_cursor,Gtk.libgdk),Nothing,(Ptr{Nothing},Ptr{Nothing}), wptr, cursor)
	return
end

CURSOR_DEFAULT = Gtk.C_NULL
CURSOR_PAN = gdk_cursor_new("grabbing")
CURSOR_MOVE = gdk_cursor_new("move")
CURSOR_COLRESIZE = gdk_cursor_new("col-resize")
CURSOR_ROWRESIZE = gdk_cursor_new("row-resize")
CURSOR_BOXSELECT = gdk_cursor_new("crosshair")

canvas = Canvas()
win = Gtk.Window(canvas, "WND")

@guarded function cb_mousepress(w::Ptr{Gtk.GObject}, event::Gtk.GdkEventButton, canvas)
	clist = [CURSOR_DEFAULT, CURSOR_PAN, CURSOR_MOVE,
		CURSOR_COLRESIZE, CURSOR_ROWRESIZE, CURSOR_BOXSELECT
	]
	global listindex
	listindex += 1
	if listindex > length(clist); listindex = 1; end
	gdk_window_set_cursor(canvas, clist[listindex])
	nothing #Known value
end

signal_connect(cb_mousepress, win, "button-press-event", Nothing, (Ref{Gtk.GdkEventButton},), false, canvas)

showall(win)

ma-laforge avatar Jul 27 '20 16:07 ma-laforge

seems to work on OSX

tknopp avatar Jul 27 '20 20:07 tknopp