Skip to content

Commit

Permalink
Get rid of subprocess startup dialog and present main window directly (
Browse files Browse the repository at this point in the history
…#1371)

起動オプションがマルチモード(--multi)ではなく、メインプロセスでもない
場合はメインプロセスのウインドウを最前面に表示するように起動処理を
変更します。

これはGNOMEをはじめとするGTKアプリケーションに導入されている
アプリケーションの一意性の管理(多重起動の防止)に基づいた挙動です。

注意
「ウインドウを最前面に表示する」動作はデスクトップ環境によって
挙動が異なる可能性があります。

参考文献
Betterbird/thunderbird-patches#202
  • Loading branch information
ma8ma authored Mar 30, 2024
1 parent 0f2735a commit e864cb0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion docs/manual/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ JDimはメインプロセス/サブプロセスという関係で動作する。

以下のコマンドを使い分ける事でサブプロセスの起動のしかたをコントロール出来る。

- 起動するかどうか確認してサブプロセスを起動
- `-m`を指定しないときはメインプロセスのウインドウを最前面に表示する <small>(v0.11.0-20240330 から変更)</small><br>
デスクトップ環境によって挙動が異なる可能性がある
```
$ jdim
```
Expand Down
6 changes: 6 additions & 0 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3197,6 +3197,12 @@ void Core::exec_command()
else if( command.command == "quit_jd" ) slot_quit();


// メインウインドウを最前面に表示する
// NOTE: "最前面に表示" はデスクトップ環境によって挙動が異なる可能性がある
else if( command.command == "present_mainwin" ) {
m_win_main.present( static_cast<guint32>( g_get_monotonic_time() / 1000 ) );
}

// 最大化/最大化解除
else if( command.command == "maximize_mainwin" ){

Expand Down
4 changes: 4 additions & 0 deletions src/iomonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ bool IOMonitor::slot_ioin( Glib::IOCondition io_condition )
MISC::ERRMSG( "IOMonitor::slot_ioin(): read error." );
}

if( buffer == kURL_WinMain ) {
core_set_command( "present_mainwin" );
return true;
}
// FIFOに書き込まれたURLを開く
// "現在のタブ/新しいタブ"など、開き方を選ぶ必要があるかも知れない
//core_set_command( "open_article", buffer, "left", "auto" );
Expand Down
3 changes: 3 additions & 0 deletions src/iomonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace CORE
{
/// @brief メインウインドウの仮想URL
constexpr const char* kURL_WinMain = "jdwin://main";

enum
{
FIFO_OK = 0,
Expand Down
12 changes: 5 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,13 @@ bool App::setup_fifo( std::string url )
// マルチモードでなく、メインプロセスでもない場合は終了
if( ! multi_mode && ! iomonitor.is_main_process() ) return false;
}
// マルチモードでなく、メインプロセスでもない場合は問い合わせる
// マルチモードではなく、メインプロセスでもない場合はメインプロセスのウインドウを最前面に表示して終了する
// NOTE: "最前面に表示" はデスクトップ環境によって挙動が異なる可能性がある
else if( ! multi_mode && ! iomonitor.is_main_process() )
{
Gtk::MessageDialog mdiag( "JDimは既に起動しています。起動しますか?\n\n起動中のJDimが存在しない場合\n"
+ CACHE::path_lock() + " を削除してください。",
false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO );
mdiag.set_title( "ロックファイルが見つかりました" );
const int ret = mdiag.run();
if( ret != Gtk::RESPONSE_YES ) return false;
// FIFOに書き込む
iomonitor.send_command( CORE::kURL_WinMain );
return false;
}
}
// FIFOに問題がある(FATで作成出来ないなど)
Expand Down

0 comments on commit e864cb0

Please sign in to comment.