xyb3rt / sxiv

Simple X Image Viewer
GNU General Public License v2.0
1.8k stars 263 forks source link

Dependent fullscreen mode #450

Open slideray opened 3 years ago

slideray commented 3 years ago

I'm trying to implement the ability to switch modes depending on the state of the window.

The idea is that the image (MODE_IMAGE) should always be viewed in a full-screen state. And the thumbnail view mode (MODE_THUMB) should always be non-fullscreen.

I do not know the language, I tried to think logically and here is what the function turned out to be:

bool cg_switch_mode_fullscreen(arg_t _)
{

  if (mode == MODE_IMAGE) {
    if (tns.thumbs == NULL)
      tns_init(&tns, files, &filecnt, &fileidx, &win);
    img_close(&img, false);
    reset_timeout(reset_cursor);
    if (img.ss.on) {
      img.ss.on = false;
      reset_timeout(slideshow);
    }
    if (ATOM__NET_WM_STATE_FULLSCREEN == false)
    tns.dirty = true;
    mode = MODE_THUMB;
  }

  if (mode == MODE_IMAGE) {
    if (tns.thumbs == NULL)
      tns_init(&tns, files, &filecnt, &fileidx, &win);
    img_close(&img, false);
    reset_timeout(reset_cursor);
    if (img.ss.on) {
      img.ss.on = false;
      reset_timeout(slideshow);
    }
    if (ATOM__NET_WM_STATE_FULLSCREEN == true)
    tns.dirty = true;
    mode = MODE_THUMB;
    win_toggle_fullscreen(&win);
  }

  if (mode == MODE_THUMB) {
    if (ATOM__NET_WM_STATE_FULLSCREEN == true)
    load_image(fileidx);
    mode = MODE_IMAGE;
  }

  else {
    if (ATOM__NET_WM_STATE_FULLSCREEN == false)
      load_image(fileidx);
    mode = MODE_IMAGE;
    win_toggle_fullscreen(&win);
  }

  return true;
}