You are not logged in.

#26 2022-01-03 10:39:43

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Thanks, I found the root of the problem, now all the dialog windows open properly and the xpm also doesn't act up. It was just a wrong window type when creating the dialogs:

diff --git a/src/gtkwidgets.c b/src/gtkwidgets.c
index c7d9c02..31a85f8 100644
--- a/src/gtkwidgets.c
+++ b/src/gtkwidgets.c
@@ -64,7 +64,7 @@ make_dialog_window( const char *title, void *callback_close )
 {
        GtkWidget *dialog_window_w;
 
-       dialog_window_w = gtk_window_new( GDK_WINDOW_DIALOG );
+       dialog_window_w = gtk_window_new( GTK_WINDOW_TOPLEVEL );
        gtk_window_set_title( GTK_WINDOW(dialog_window_w), title );
        gtk_container_set_border_width( GTK_CONTAINER(dialog_window_w), 0 );
        if (callback_close != NULL) {

Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#27 2022-01-03 11:11:07

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [Solved] Struggling with C and GTK

Maybe all this could be simplified by using GtkDialog, available in GTK 2 (I don't know if it existed in GTK, I can't find a doc): https://developer-old.gnome.org/gtk2/2. … ialog.html

Offline

#28 2022-01-03 13:15:05

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

That would be quite cool, actually, but I am a bit stuck with it: gtk_dialog_new_with_buttons() requires the parent window object as argument, but it is not available in the scope where gtk_dialog_new_with_buttons() is being called. So I need to pass it to this scope to make it available. But gtk_dialog_new_with_buttons() is called inside, for example, dialog_Help_About(), which creates the About dialog, and this dialog_Help_About() is called as a callback in a gtk_signal_connect(). But gtk_signal_connect() accepts only one callback_data argument which is already used for something else, and thus I cannot pass the parent window object to the scope where I need it to be...

Stupid question: Is it possible to define a "global" variable inside a function, such that it is available in all functions called inside our function without being explicitly passed as argument?

Last edited by PhotonX (2022-01-03 13:16:52)


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#29 2022-01-03 14:13:52

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: [Solved] Struggling with C and GTK

You should have the widget/pressed button in the callback, so use "gtk_widget_get_toplevel(widget)"


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#30 2022-01-03 14:52:41

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [Solved] Struggling with C and GTK

PhotonX wrote:

But gtk_signal_connect() accepts only one callback_data argument which is already used for something else, and thus I cannot pass the parent window object to the scope where I need it to be...

Probably what @progandy says is enough in this case, otherwise in general you have to define and allocate (and then release) a structure to put the data you want to pass to the callback.
This gives you a pointer that you pass as the only data.

Otherwise, when one of the data to be passed is a GObject (as is very often the case in this context), you can attach temporary data to it using the g_object_set_data() function family.
You should not abuse it as the doc says, but it is very convenient.

Offline

#31 2022-01-03 15:54:54

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Thanks guys, this works!

____________
edit:
Sorry, please disregard what comes below, I solved it just after posting... I had to add

active = FALSE;

before the

gtk_widget_hide (about_window_w);

call!
____________

However, now I am stuck with closing the dialog. Previously in the function

dialog_Help_About( GtkWidget *widget, int *message )

there was a

add_button( main_vbox_w, STR_DLG_Okay_btn, dialog_Help_About, MESG_(DIALOG_CLOSE) );

call which sent a DIALOG_CLOSE message and used the function itself as callback. It would check, what the message is, and hide the dialog:

	switch (*message) {
	case DIALOG_OPEN:
		if (active)
			return;
		active = TRUE;
		break;

	case DIALOG_CLOSE:
		if (!active)
			return;
		active = FALSE;
		gtk_widget_hide( about_window_w );
		return;

	default:
#ifdef DEBUG
		crash( "dialog_Help_About( ): invalid message" );
#endif
		return;
	}

However, now the dialog object allows to create a button automatically. So now I have two OK buttons: One added via add_button as explained above, one created automatically via

	about_window_w = gtk_dialog_new_with_buttons(STR_DLG_About,
                             GTK_WINDOW(parent_window),
                             GTK_DIALOG_MODAL,
                             GTK_STOCK_OK
                             );

To make this latter OK button do something I added

	gint result = gtk_dialog_run (GTK_DIALOG (about_window_w));

	gtk_widget_hide (about_window_w);

This does not work as expected, however, to be more precise, it works only once, if clicked the default OK button once, the dialog is hidden and then never shown again when the menu entry is clicked.

Here is the complete function: https://gist.github.com/Photon89/513478 … 51dc1c8526

Here is how it looks like (upper OK button is added by hand and works, lower OK button is added automatically on dialog creation and works only once):

dHCmpNT.png

Last edited by PhotonX (2022-01-03 16:02:22)


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#32 2022-01-04 11:55:45

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Hi guys,

it's me again. smile I now ran into X errors and try to debug them:

$ gdb
GNU gdb (GDB) 11.1
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) file src/lightspeed
Reading symbols from src/lightspeed...
(gdb) break gdk_x_error
Function "gdk_x_error" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (gdk_x_error) pending.
(gdb) run --sync
Starting program: /home/photon/github/lightspeed2/src/lightspeed --sync
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
/home/photon/github/lightspeed2/src/lightspeed: unrecognized option '--sync'
[New Thread 0x7ffff6287640 (LWP 39981)]
[Thread 0x7ffff6287640 (LWP 39981) exited]
[New Thread 0x7ffff6287640 (LWP 39982)]
[New Thread 0x7ffff5762640 (LWP 39983)]
[New Thread 0x7ffff6287640 (LWP 39984)]
[Thread 0x7ffff6287640 (LWP 39982) exited]
[New Thread 0x7ffff4e31640 (LWP 39985)]
[Thread 0x7ffff5762640 (LWP 39983) exited]
[New Thread 0x7ffff5762640 (LWP 39986)]
[Thread 0x7ffff6287640 (LWP 39984) exited]
[New Thread 0x7ffff6287640 (LWP 39987)]
[Thread 0x7ffff5762640 (LWP 39986) exited]
[Thread 0x7ffff4e31640 (LWP 39985) exited]
[Thread 0x7ffff6287640 (LWP 39987) exited]

(lightspeed:39977): Gdk-CRITICAL **: 12:49:57.143: IA__gdk_string_width: assertion 'font != NULL' failed
[New Thread 0x7ffff6287640 (LWP 39988)]
[New Thread 0x7ffff4e31640 (LWP 39989)]
[New Thread 0x7ffff5762640 (LWP 39990)]
[New Thread 0x7fffe4af4640 (LWP 39991)]
[New Thread 0x7fffdffff640 (LWP 39992)]
[Thread 0x7fffe4af4640 (LWP 39991) exited]
[New Thread 0x7fffe4af4640 (LWP 39993)]
[Thread 0x7fffdffff640 (LWP 39992) exited]
[New Thread 0x7fffe4af4640 (LWP 39994)]
[Thread 0x7fffe4af4640 (LWP 39993) exited]
[Thread 0x7fffe4af4640 (LWP 39994) exited]
The program 'lightspeed' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadValue (integer parameter out of range for operation)'.
  (Details: serial 7625 error_code 2 request_code 151 minor_code 3)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
^C
Thread 1 "lightspeed" received signal SIGINT, Interrupt.
0x00007ffff6c68740 in _XReply () from /usr/lib/libX11.so.6
(gdb) bt
#0  0x00007ffff6c68740 in _XReply () at /usr/lib/libX11.so.6
#1  0x00007ffff6c63fbd in XSync () at /usr/lib/libX11.so.6
#2  0x00007ffff6c6405c in  () at /usr/lib/libX11.so.6
#3  0x00007ffff42d9626 in  () at /usr/lib/libGLX_nvidia.so.0
#4  0x00007ffff427c060 in  () at /usr/lib/libGLX_nvidia.so.0
#5  0x00007ffff42b6fae in  () at /usr/lib/libGLX_nvidia.so.0
#6  0x00007ffff42ba711 in  () at /usr/lib/libGLX_nvidia.so.0
#7  0x00007ffff4279990 in  () at /usr/lib/libGLX_nvidia.so.0
#8  0x00007ffff427a19f in  () at /usr/lib/libGLX_nvidia.so.0
#9  0x00007fffffffc698 in  ()
#10 0x00007ffff62c6338 in  () at /usr/lib/gtk-2.0/2.10.0/engines/libmurrine.so
#11 0x00007fffffffc910 in  ()
#12 0x00007ffff4315009 in  () at /usr/lib/libGLX_nvidia.so.0
#13 0x00007fffffffc910 in  ()
#14 0x00007ffff7fdd1c5 in _dl_fini () at /lib64/ld-linux-x86-64.so.2
(gdb) quit
A debugging session is active.

	Inferior 1 [process 39977] will be killed.

Quit anyway? (y or n) y

As you see, the "--sync" option is not being recognized and the backtrace comes too late, after I Ctrl+C the crashed process. What do I do wrong?

I assume that the errors are due to g_object_unref() and gdk_gl_pixmap_unref() calls in https://github.com/Photon89/lightspeed/ … shot.c#L89 which I had to remove (I also tried to substitute them with g_object_unref() but it doesn't make a difference). But maybe the problem is somewhere else...

addendum: I fear, my guess is wrong, the X error also appears in the GTK+ version, which I didn't touch...

Last edited by PhotonX (2022-01-04 12:05:10)


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#33 2022-01-04 20:52:53

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Hi guys,

I deactivated the snapshot export functionality for the moment (we have screenshot tools nowadays anyway) and created an AUR package for the current progress: https://aur.archlinux.org/packages/lightspeed-git/


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#34 2022-01-05 21:17:16

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Hi guys,

I attempted to port this thing further, to GTK3: https://github.com/Photon89/lightspeed/pull/8 It already compiles, links and runs. But the OpenGL output is all black. I have removed some things to make it compile, in particular all the text overlay stuff, which is implemented in a completely different way in GTK3 (no GdkFont, Pango stuff instead). But I left all the non-text related OpenGL code, besides of

gtk_gl_area_swap_buffers()

calls. The ogl_draw() function is executed and uses the correct "camera" widget, that is the only thing I know, but I I don't know how to find out where it breaks inside this function. Maybe it's really just this gtk_gl_area_swap_buffers() call which is missing for a proper output.

But even if so, according to https://www.bassi.io/articles/2015/02/1 … -with-gtk/ this is quite a biggie and would require to really understand big portions of the code to be able to rewrite them. In this case, I fear, I'm out... But maybe something can be done to make OpenGL output work in GTK3 with less effort?


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#35 2022-01-06 13:40:16

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Hi guys,

with some hints I could make OpenGL debugging work and now see that all the GL related code doesn't work in OpenGL versions later than 3.1 (currently we are at 4.6 so I am a bit late to the party...). It looks like this time the strategy of exchanging some function calls with newer ones, which are mostly doing the same and just have a different name, won't work any more because OpenGL now seems to work with a completely different approach.

So the worst case scenario is that it is necessary to learn the old version's API to understand how the current code is working, the new version's API to understand what possibilities there are now, and try to completely reimplement what the old code was doing. I am wondering, whether there is some kind of migration guide, which of course won't be a one-to-one dictionary of old and new functions, but at least gives some hints for people that need to do such a migration? I mean, how hard can it be to understand and reimplement around 500 code lines! big_smile

Last edited by PhotonX (2022-01-06 13:41:31)


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#36 2022-01-06 13:59:42

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: [Solved] Struggling with C and GTK

Older GL versions might work if you use gtk_gl_area_set_required_version. (There might be a limit if gtk/gdk itself requires a minimum version)
https://docs.gtk.org/gtk3/method.GLArea … rsion.html

Last edited by progandy (2022-01-06 14:03:08)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#37 2022-01-06 14:45:49

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Good idea, but:

(lightspeed:26482): Gdk-WARNING **: 15:44:40.894: gdk_gl_context_set_required_version - GL context versions less than 3.2 are not supported.

Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#38 2022-01-06 16:55:47

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [Solved] Struggling with C and GTK

PhotonX wrote:

I am wondering, whether there is some kind of migration guide, which of course won't be a one-to-one dictionary of old and new functions, but at least gives some hints for people that need to do such a migration?

GTK provides a migration guide when moving from one major version to another.
You've probably already seen it, but I give the links just in case:
* GTK to GTK 2: https://developer-old.gnome.org/gtk2/2. … ating.html
* GTK 2 to GTK 3: https://developer-old.gnome.org/gtk3/st … ating.html
But there doesn't seem to be much about OpenGL, and for your specific problem I don't know, sorry sad

Offline

#39 2022-01-06 17:29:57

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: [Solved] Struggling with C and GTK

Thanks, I have indeed some quirks left which are GTK3 related, in particular font related stuff. But the most pressing problem is OpenGL related now, as there is no point in solving other problems, if the OpenGL output is broken and too tough to fix.

Anyway, thanks a ton to both of you guys, I learned a lot about C, GTK and coding in general and had a lot of fun with this little project in my Christmas break. I think, the initial GTK related issues are all solved, we even have a completely functional GTK2 version now, so I'd rather mark this thread as solved and open a new one about the OpenGL related stuff. Maybe it will catch the attention of some GL specialist. smile

Last edited by PhotonX (2022-01-06 17:40:50)


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

Board footer

Powered by FluxBB