窗口管理器警报弹出窗口超时

时间:2018-06-30 15:25:37

标签: c++ linux timeout x11 xlib

我正在使用带有弹出警报的窗口管理器,如果用户未单击它们,我希望它们在10秒后自动隐藏。该警报在没有超时代码的情况下正常工作 。我具有以下功能:

void ShowAlert(int Index) {
    // create the window containing the alert
    Fl_Window* Alert = new Fl_Window(100, 100, STYLING.alert__width, STYLING.alert__height, NULL);

    ...construct the popup...

    // show the alert
    Alert->show();

    // now we need to implement the timeout so if it isn't clicked, it will hide on its own
    // TRY 1
    //  sleep(10);
    //  Alert->hide();

    // TRY 2
    //  std::this_thread::sleep_for(std::chrono::milliseconds(10000));
    //  Alert->hide();

    // TRY 3
    //  unsigned long seconds = 10;
    //  timer t;
    //  t.start();
    //  while(true) {
    //      if(t.elapsedTime() >= seconds) { break; }
    //      else { sleep(1); }
    //  }

    // TRY 4
    pid_t pid;
    switch ((pid = fork())) {
        case -1:            // the fork() has failed
            break;
        case 0:             // this is processed by the child
            sleep(10);
            Alert->hide();
            exit(0);
            break;
        default:            // this is processed by the parent
            break;
    }
}

TRY 1无效,因为弹出窗口永远不会显示,然后WM在调用“ Alert-> hide();”时崩溃了。之后。

TRY 2做过同样的事情 (请参阅Sleep for milliseconds

TRY 3做过同样的事情 (请参阅http://www.cplusplus.com/forum/beginner/317/

TRY 4显示了警报,但超时似乎无法在10秒后隐藏弹出窗口

这是在使用Xlib和FLTK的Linux系统上。任何帮助将不胜感激!

0 个答案:

没有答案