Skip to content
This repository has been archived by the owner on Jul 12, 2018. It is now read-only.

Getting window size #29

Closed
Arood opened this issue Jul 26, 2016 · 10 comments
Closed

Getting window size #29

Arood opened this issue Jul 26, 2016 · 10 comments

Comments

@Arood
Copy link

Arood commented Jul 26, 2016

Hello!

I've tried this library and it seems to work for the most part! I'm having some trouble though that I hope someone can guide me with. I'm trying to figure out the size of a GtkWindow when a user resizes it. I found a signal that works, 'check-resize', but I can't figure out how to get the actual size of the window.

It seems like GTK isn't tracking this by itself, but via GDK, so it seems like the easiest way would normally be using the get_allocation method and then read width and height from there. However, it seems like I can't get this from node-gtk.

Of course, get_request_size doesn't work since it's not the actual size of the window.

Does anyone have any suggestions for how I can access the size in node-gtk?

@WebReflection
Copy link
Owner

Are you sure you don't have a win.get_size() in there?

On Tue, Jul 26, 2016 at 4:01 PM, Marcus Olovsson notifications@github.com
wrote:

Hello!

I've tried this library and it seems to work for the most part! I'm having
some trouble though that I hope someone can guide me with. I'm trying to
figure out the size of a GtkWindow when a user resizes it. I found a signal
that works, 'check-resize', but I can't figure out how to get the actual
size of the window.

It seems like GTK isn't tracking this by itself, but via GDK, so it seems
like the easiest way would normally be using the get_allocation method
and then read width and height from there. However, it seems like I can't
get this from node-gtk.

Of course, get_request_size doesn't work since it's not the actual size of
the window.

Does anyone have any suggestions for how I can access the size in node-gtk?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#29, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAFO9SCSAxq9tP5u9-bUPCccAZZssQFgks5qZiFIgaJpZM4JVPez
.

@Arood
Copy link
Author

Arood commented Jul 26, 2016

Ah sorry, forgot to mention, I've tried that as well. It only returns undefined for me. Just to double-check that I didn't do anything wrong, I made an isolated example:

var
  GNode = require('node-gtk'),
  Gtk = GNode.importNS('Gtk'),
  settings,
  win
;

GNode.startLoop();
Gtk.init(null);

win = new Gtk.Window({
  title: 'node-gtk',
  window_position: Gtk.WindowPosition.CENTER
});

win.connect('check-resize', function() {
  console.log(win.get_size());
});

win.connect('show', Gtk.main);
win.connect('destroy', Gtk.main_quit);

win.set_default_size(200, 80);
win.add(new Gtk.Label({label: 'Hello Gtk+'}));

win.show_all();

@WebReflection
Copy link
Owner

Weird, maybe it's one of those parts missing from the module, which has been kinda, and unfortunately, abandoned.

This one though, works without problem via jsgtk

#!/usr/bin/env jsgtk
var
  Gtk = require('Gtk'),
  settings,
  win
;

Gtk.init(null);

win = new Gtk.Window({
  title: 'jsgtk',
  window_position: Gtk.WindowPosition.CENTER
});

win.connect('check-resize', function() {
  console.log(win.get_size());
});

win.connect('show', Gtk.main);
win.connect('destroy', Gtk.main_quit);

win.set_default_size(200, 80);
win.add(new Gtk.Label({label: 'Hello Gtk+'}));

win.show_all();

@magcius
Copy link
Collaborator

magcius commented Jul 26, 2016

Yeah, I haven't gotten that much time to work on this, and I haven't convinced anyone at Endless that this is something we should spend time on.

@WebReflection
Copy link
Owner

WebReflection commented Jul 26, 2016

I wonder if I should just flag this as deprecated on both npm and the README

It's such a pity GJS folks never even thought about helping us, neither here nor in the jsgtk repo.

This is for now, I believe, a won't fix, but just to provide how at least jsgtk moved forward with ES6 support and camelCase-ability

#!/usr/bin/env jsgtk

const Gtk = require('Gtk');

Gtk.init(null);

const win = new Gtk.Window({
  title: 'jsgtk',
  windowPosition: Gtk.WindowPosition.CENTER
});

win
  .on('check-resize', () => {
    console.log(win.getSize());
  })
  .on('show', Gtk.main)
  .on('destroy', Gtk.mainQuit)
;

win.setDefaultSize(200, 80);
win.add(new Gtk.Label({label: 'Hello Gtk+'}));

win.showAll();

@Arood
Copy link
Author

Arood commented Jul 26, 2016

Too bad, my reasoning for using node-gtk instead of jsgtk was that the project I'm working on is a cross-platform one (with other modules for gui on other platforms), and it felt like it would make sense to use the same interpreter. I wish I could contribute to this project but my C++-fu isn't very good, I haven't even figured out how to build the project. I'll try jsgtk for now, we'll see if I can revisit this project in the future. Thanks for the quick response!

@WebReflection
Copy link
Owner

WebReflection commented Jul 26, 2016

Everyone that tried to hook into GobjectIntrospection via NodeJS abandoned the idea due too much effort for apparently low demand.

Gtk3 seems to be maintained by a niche ... that unfortunately want to keep it for a niche.
It would gain way more attention if based on V8 and with a Wayland capable, cross platform, ChromiumGtk but Googlers decided to abandon Gtk already a while ago and MacPorts chaps don't even see that basing everything on Quartz instead of X11 would benefit everyone.

Sad idea/repo/potentials story is sad ¯\_(ツ)_/¯

@magcius
Copy link
Collaborator

magcius commented Jul 26, 2016

Google didn't abandon GTK+, they still use it for file picker dialogs and such. I think there's a bit of hope now inside Endless to devote resources this to it with some new development, so I'm talking with a few colleagues right now.

@Arood
Copy link
Author

Arood commented Jul 26, 2016

Like both of you have mentioned, it seems to be low demand right now, but I believe it still has potential. But sadly I think we can still forget to get any help from the Gtk3 maintainers, it simply feels like something that has to be maintained by someone who use it. I hope I can help in the future but I need to study building node-modules first :)

@romgrk
Copy link

romgrk commented Jul 27, 2016

Just to mention, my fork of this does does handle the get_allocation(). Though it's not at all ready for any kind of serious usage. (Busy with work too)

const gtk = require('node-gtk').require('Gtk', '3.0')
gtk.init();
win = new gtk.Window()
// …
win.getAllocation() //  =>  GdkRectangle {}
win.getAllocation().width //  =>  600
win.getAllocation().height //  =>  731

This was referenced Jul 27, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants