# How to display an image in full screen on a second monitor?

**URL:** https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796
**Category:** Signal and Image Processing
**Tags:** gtk
**Created:** [June 24, 2023, 11:07pm UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796 "2023-06-24T23:07:46Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![marcsgil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcsgil/32/33908_2.png) [@marcsgil](https://discourse.julialang.org/u/marcsgil)
#### Post date: [June 24, 2023, 11:07pm UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796/1 "2023-06-24T23:07:46Z")

</div>

Hello!

I’m currently working on developing a program to control a Spatial Light Modulator (SLM), which is a lab equipment used in the field of Structured Light. Essentially, an SLM allows for the projection of interesting shapes onto a laser beam.

From the programming point of view, we simply need to know that an SLM is a small monitor attached to your PC, in which we need to display images.

For a program to effectively control an SLM, it should have the following functionalities:

- Display a grayscale image in full screen on a second monitor, without any additional elements being shown.
- Allow for dynamic changes to the displayed image.

I came across the [slmpy](https://github.com/wavefrontshaping/slmPy) package, which precisely fulfills these requirements. However, it is built in Python, utilizing the wxPython module.

While exploring GUI packages in Julia, I haven’t found an obvious candidate for this task. I’m familiar with [ImageView.jl](https://github.com/JuliaImages/ImageView.jl), but unfortunately, it is unusable for me due to a [known problem with GTK.jl on Windows](https://github.com/JuliaGraphics/Gtk.jl/issues/629).

Do you have any suggestions on how I can accomplish this in Julia? Thanks!

---

<div class="post-metadata">

### Author: ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)
#### Post date: [June 24, 2023, 11:35pm UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796/2 "2023-06-24T23:35:08Z")

</div>

I haven’t tried this myself, but if there isn’t a native tool, you could serve a very simple website with a websocket to a browser that updates the current image. Then just `F11` the browser into full screen on your second monitor.

Edit: maybe @ndortega could shed light on whether Oxygen.jl might help if you go the local-web route?

---

<div class="post-metadata">

### Author: ![jwahlstrand](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@jwahlstrand](https://discourse.julialang.org/u/jwahlstrand)
#### Post date: [June 25, 2023, 2:56am UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796/3 "2023-06-25T02:56:49Z")

</div>

I use [Gtk4.jl](https://github.com/JuliaGtk/Gtk4.jl) for this very application, displaying a grayscale image to control an SLM. You can get a list of connected monitors and fullscreen a window on a particular one. We identify our SLM by the tiny physical size it reports – we have no other 12 mm tall monitors! A separate window has controls so that we can dynamically control the phase mask we send to the SLM. In the lab I work in we use a Linux computer for this, and it has worked very smoothly so far. We have to update the calibration (when we need to) using the proprietary software that came with the SLM, with a USB connection to a separate (Windows) computer. But for sending masks to the SLM it’s great to be able to have Julia generate and display images instead of generating a bunch of TIFF files and then picking them out of a directory.

At this point, Gtk4.jl is at feature parity with Gtk.jl, and because it does not suffer from that upstream GTK3 issue you linked to, Gtk4.jl works much better on Windows. I do notice some REPL slowness on Windows, but it’s not extreme. I actually notice roughly the same amount of lag when I use PyPlot.jl on Windows.

However, unfortunately GTK4’s fullscreen mode on Windows is buggy (see [fullscreen(win) causes entire frame to blink and children of window to become unresponsive. · Issue #30 · JuliaGtk/Gtk4.jl · GitHub](https://github.com/JuliaGtk/Gtk4.jl/issues/30)). Just showing an image _may_ work but I hesitate to recommend it. We can’t use Windows computers to control our SLM anyway, because we don’t have administrative control over the screen lock on Windows computers, which results in the SLM mask going blank after 15 minutes of inactivity.

---

<div class="post-metadata">

### Author: ![marcsgil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcsgil/32/33908_2.png) [@marcsgil](https://discourse.julialang.org/u/marcsgil)
#### Post date: [June 25, 2023, 11:57am UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796/5 "2023-06-25T11:57:22Z")

</div>

That’s great! Would you mind sharing your code?

---

<div class="post-metadata">

### Author: ![jwahlstrand](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@jwahlstrand](https://discourse.julialang.org/u/jwahlstrand)
#### Post date: [June 25, 2023, 2:12pm UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796/6 "2023-06-25T14:12:42Z")

</div>

To determine which “monitor” is the SLM, we use:

```julia
using Gtk4

monitor_list = Gtk4.monitors() # list of monitors
isSLM(m) = (m.height_mm < 25) # in our case, this works. Other properties may be 
                                # populated for your SLM, like manufacturer or model

i = findfirst(isSLM, monitor_list)
if i === nothing
    error("SLM could not be found")
end
slm = monitor_list[i]

```

We create a window with a widget to display the image, and then call `Gtk4.G_.fullscreen_on_monitor(window, slm)` to fullscreen a `GtkWindow` on that monitor. That works on Linux at least, not sure about Windows.

For display widgets, there are many options:  
• `GtkPicture` displays a `GdkPixbuf` image, which you can construct from an array.  
• `GtkDrawingArea` uses Cairo to draw arbitrary images. This is what’s used in ImageView.jl, and it works exactly the same in Gtk4.jl and Gtk.jl.  
• There is a separate package, `Gtk4Makie`, that can show a Makie figure in a Gtk4 window. You could use Makie’s `image` method to draw something using that. By the way, you might be able to avoid GTK altogether by using GLMakie, which uses a different cross platform library (GLFW) to show windows. I am not sure if it’s possible in GLFW to control where the window gets fullscreened.

If you use `GtkPicture`, the code would be something like:

```julia
p = GtkPicture()
win = GtkWindow(p) # make a window with `p` as its only child
Gtk4.G_.fullscreen_on_monitor(window,slm) # this will be wrapped nicely in Gtk4.jl soon

m = Matrix{GdkPixbufLib.RGB}(undef,1920,1152)
pb = GdkPixbuf(m,false) # false here means no alpha channel

function change_mask(m) # could add other arguments to control what gets written
    # fill in the matrix `m` here
    Gtk4.pixbuf(p,pb) # need to call this to refresh the picture
end

change_mask(m)

```

I don’t have access to the code currently, so I may come back and edit this.

---

<div class="post-metadata">

### Author: ![marcsgil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcsgil/32/33908_2.png) [@marcsgil](https://discourse.julialang.org/u/marcsgil)
#### Post date: [June 25, 2023, 10:35pm UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796/7 "2023-06-25T22:35:25Z")

</div>

Thank you for your suggestions! I’m actually considering all of them.

Regarding the code you just sent, I wasn’t able to make it work properly. I’m able to display a random grayscale image in fullscreen, but it appears on my main monitor, instead of the secondary one.

Here is my adaptation of your code:

```julia
using Gtk4

monitor_list = Gtk4.monitors()
slm = monitor_list[2] #Second monitor. Changing 2 to 1 doesn't make a difference

p = GtkPicture()
win = GtkWindow(p) 
Gtk4.G_.fullscreen_on_monitor(win,slm) 

convert2rgb(x) = Gtk4.GdkPixbufLib.RGB(x,x,x) #Converts numbers to gray

m = convert2rgb.(rand(UInt8,size(slm)...)) #Random grayscale image
pb = Gtk4.GdkPixbuf(m,false)
Gtk4.pixbuf(p,pb)

```

Are there any mistakes or do you think it can be due to the Windows related issues that you mentioned?

---

<div class="post-metadata">

### Author: ![jwahlstrand](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@jwahlstrand](https://discourse.julialang.org/u/jwahlstrand)
#### Post date: [June 27, 2023, 1:13am UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796/8 "2023-06-27T01:13:03Z")

</div>

Argh, I tried this on Windows today and, indeed, it fullscreens on the main monitor, not the one specified. To be fair, I guess there is sort of a warning in the documentation that this may not work: [Gtk.Window.fullscreen\_on\_monitor](https://docs.gtk.org/gtk4/method.Window.fullscreen_on_monitor.html).

---

<div class="post-metadata">

### Author: ![Ashwani\_Rathee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashwani_rathee/32/49551_2.png) [@Ashwani\_Rathee](https://discourse.julialang.org/u/Ashwani_Rathee)
#### Post date: [June 27, 2023, 5:59am UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796/9 "2023-06-27T05:59:13Z")

</div>

@marcsgil Can you please add the domain tag #Signal and Image Processing so we can keep track of this issue there.

---

<div class="post-metadata">

### Author: ![marcsgil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcsgil/32/33908_2.png) [@marcsgil](https://discourse.julialang.org/u/marcsgil)
#### Post date: [June 27, 2023, 11:09am UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796/10 "2023-06-27T11:09:12Z")

</div>

Should I open an issue in Gtk4.jl?

---

<div class="post-metadata">

### Author: ![marcsgil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcsgil/32/33908_2.png) [@marcsgil](https://discourse.julialang.org/u/marcsgil)
#### Post date: [June 27, 2023, 11:10am UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796/11 "2023-06-27T11:10:09Z")

</div>

Sure, but I can’t find the edit button in the post 😅 . Could you point me to it?

---

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [June 27, 2023, 11:35am UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796/12 "2023-06-27T11:35:34Z")

</div>

It’s next to the title (I edited it for you now).

---

<div class="post-metadata">

### Author: ![jwahlstrand](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@jwahlstrand](https://discourse.julialang.org/u/jwahlstrand)
#### Post date: [June 27, 2023, 12:15pm UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796/13 "2023-06-27T12:15:19Z")

</div>

This is definitely an issue with the GTK4 library, not Gtk4.jl, so [GNOME / gtk · GitLab](http://gitlab.gnome.org/GNOME/gtk) would be the right place. This definitely isn’t going to be fixed any time soon, so I would look into other solutions.

---

<div class="post-metadata">

### Author: ![ndortega](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ndortega/32/37018_2.png) [@ndortega](https://discourse.julialang.org/u/ndortega)
#### Post date: [June 29, 2023, 2:08am UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796/14 "2023-06-29T02:08:48Z")

</div>

Hi @mrufsvold,

I don’t have too much to add here, you summarized it pretty well. I think the only disclaimer is that integrating websockets into your server at the moment isn’t as clean as it can be. You have to create a middleware function to intercept the incoming connection [like this](https://github.com/ndortega/Oxygen.jl/pull/117). I plan on adding support for websocket routes similar to how it works in FastApi & Sanic.

But with that said, I would say the main benefit of using a web server to do this would allow you to build an API on top of your core application so it can easily integrate with other systems.

Of course, this approach requires you to write Julia, Javascript, and HTML to accomplish the same task while going with GTK4.jl would be a 100% Julia solution. At the end of the day, it depends entirely on your goals because both approaches have their own tradeoffs

---

<div class="post-metadata">

### Author: ![Jakub\_Mitura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakub_mitura/32/19496_2.png) [@Jakub\_Mitura](https://discourse.julialang.org/u/Jakub_Mitura)
#### Post date: [November 5, 2023, 3:47pm UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796/15 "2023-11-05T15:47:35Z")

</div>

A bit hacky way but you can also use my Medeye3d it opens ew window of specified size by the user set it to size of your screen and should work

---

<div class="post-metadata">

### Author: ![apieum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/apieum/32/2928_2.png) [@apieum](https://discourse.julialang.org/u/apieum)
#### Post date: [November 7, 2023, 12:41pm UTC](https://discourse.julialang.org/t/how-to-display-an-image-in-full-screen-on-a-second-monitor/100796/16 "2023-11-07T12:41:27Z")

</div>

I think it has been fixed recently, maybe try to patch your gtk lib or use a dev one.

> **[Fix resizing with native Windows decorations (30de55f3) · Commits · GNOME /...](https://gitlab.gnome.org/GNOME/gtk/-/commit/30de55f3cf062d6878e58ee54f4c45ff8a5242e0)**
>
> Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/5142 Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/5088 Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/5090
