0

I am writing a function to get x, y, width, and height of all the monitors of the multi moniotr setup.

I found this solution: https://stackoverflow.com/a/23608025/5062337

So I implemented it with jsctypes:

            var collMonInfos = [];

            var rootGdkWin = ostypes.API('gdk_get_default_root_window')();
            console.info('rootGdkWin:', rootGdkWin.toString(), uneval(rootGdkWin), cutils.jscGetDeepest(rootGdkWin));

            var rootGtkWin = ostypes.HELPER.gdkWinPtrToGtkWinPtr(rootGdkWin);

            // the screen contains all monitors
            var gdkScreen = ostypes.API('gtk_window_get_screen')(rootGtkWin);

            var fullWidth = ostypes.API('gdk_screen_get_width')(gdkScreen);
            var fullHeight = ostypes.API('gdk_screen_get_height')(gdkScreen);

            console.info('fullWidth:', fullWidth.toString(), 'fullHeight:', fullHeight.toString());

            // collect data about each monitor
            var monitors = [];
            var nmons = ostypes.API('gdk_screen_get_n_monitors')(gdkScreen);
            console.info('number of monitors:', nmons);
            nmons = cutils.jscGetDeepest(nmons);

            var rect = ostypes.TYPE.GdkRectangle();
            for (var i=0; i<nmons; i++) {
                var mg = ostypes.API('gdk_screen_get_monitor_geometry')(gdkScreen, i, rect.address());
                collMonInfos.push({
                    x: cutils.jscGetDeepest(rect.x),
                    y: cutils.jscGetDeepest(rect.y),
                    w: cutils.jscGetDeepest(rect.width),
                    h: cutils.jscGetDeepest(rect.height)
                })
            }

            return collMonInfos;

However this tells me I have 0 monitors.

So I was wondering, starting with gdk_default_root_window, how to get info on all the monitors?

I know I can get the union of all monitors with gdk_drawable_get_size but i need individual monitor information please.

Thanks

Community
  • 1
  • 1
yatg
  • 1,121
  • 1
  • 9
  • 15
  • 1
    However your `gdkWinPtrToGtkWinPtr` is implemented, it can't do what you seem to expect it to. The root window almost certainly has no matching GTK Window. Why not just call gdk_window_get_screen() on the root GDK window? – Jussi Kukkonen Jul 17 '15 at 10:41
  • Thanks @jku Ill try that! :) – yatg Jul 17 '15 at 17:31

0 Answers0