java - Get Active Shell in SWT, even if the Shell is not on focus -
display.getactiveshell()
seems consider shell active if it's focused. if @ moment application has focus means display.getactiveshell()
returns null
.
i need method tell me shell on focus on swt application, when swt application not on focus.
i've hacked piece of code together, although assertionexception
:
public static shell getactiveshell() { display display = display.getdefault(); shell result = display.getactiveshell(); if (result == null) { shell[] shells = display.getshells(); (shell shell : shells) { if (shell.getshells().length == 0) { if (result != null) throw new assertionexception(); result = shell; } } } return result; }
is there standard way approach issue other writing own method?
recently, had similar problem , though found solution in meanwhile i'd share mine future reference.
the shellactivationtracker
adds display filter listens activate
events , - if activated widget shell
- remembers activated shell
. can query (last) active shell if application not active/focused.
class shellactivationtracker implements listener { shell activeshell; shellactivationtracker( display display ) { activeshell = display.getactiveshell(); display.addfilter( swt.activate, ); } @override public void handleevent( event event ) { if( event.widget instanceof shell ) { activeshell = ( shell )event.widget; } } }
Comments
Post a Comment