Gnome’s Run Command Dialog

Since I switched to Ubuntu, I missed a Run Command dialog ala Windows. Somehow I think it lots neater than the “classic” terminal window. Actually the dialog is provided in Add To Panel dialog. But I don’t know why it can’t be placed on Gnome’s main menu. It kinds of a weird “policy” of Gnome, IMO. So, I started to google (yes, now google can be used as verb) about this issue. I found many people also miss the dialog.

Then, google took me to this blog. The blog owner has a small program to pop up Gnome’s Run Command dialog. As it’s a program, we are able to put its shortcut in the main menu. That’s just exactly what I need.

Happily I downloaded the source, compile it with gcc, and run it. As expected, it works. Still, there’s a but, a big but to me actually. The program is able to show the Run Command dialog but the window isn’t brought to the foreground. It’s very annoying! Logically, we expect a window would pop up in front of us each time we click on an application’s icon.

I uttered this problem on the blog. The blog owner suggested me to use an additional tool name Devilspie to manage Gnome’s window extra behavior. Personally, I don’t like this solution. I believe Gnome and X11 is a mature window manager with relatively complete features. Inability to bring up a window to the front sounds impossible.

So, I started to learn a little bit about x window and Gnome desktop programming. After about an hour googling around, fortunately, I found the solutions. There’s a tiny mistake on the program and it’s pretty easy to fix. But, instead of fix the c written program, I chose to re-write it in pascal using my favorite pascal compiler: FreePascal.😀

And here’s the pascal code…

1:
 
2:
 
3:
4:
 
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
 
15:
16:
 
17:
 
18:
19:
20:
21:
 
22:
23:
24:
25:
26:
27:
28:
29:
 
30:
31:
32:
 
33:
34:
35:
36:
37:
38:
39:
 
40:
41:
 
42:
43:
 
program gnome_run;

{$MODE OBJFPC}{$H+}

uses
  x, xlib, SysUtils;

function FindAtom(ADisplay: PXDisplay; const AtomName: string): TAtom;
var
  FAtom: TAtom;
begin
  FAtom := XInternAtom(ADisplay, PChar(AtomName), false);
  if FAtom = None then
  begin
    Writeln('Error: can''t find requested atom.');
    Halt;
  end;

  Result := FAtom;
end;

(******** main program ********)

var
  Display: PXDisplay;
  GnomePanelAtom, RunDialogAtom: TAtom;
  ClientEvent: TXClientMessageEvent;

begin
  // open x display
  Display := XOpenDisplay(nil);
  if Display = nil then
  begin
    Writeln('Error: can''t open X display.');
    Halt;
  end;

  // find panel atom
  GnomePanelAtom := FindAtom(Display, '_GNOME_PANEL_ACTION');
  RunDialogAtom := FindAtom(Display, '_GNOME_PANEL_ACTION_RUN_DIALOG');

  // set event properties
  ClientEvent._Type := ClientMessage;
  ClientEvent.Window := DefaultRootWindow(Display);
  ClientEvent.Message_Type := GnomePanelAtom;
  ClientEvent.Format := 32;
  ClientEvent.Data.l[0] := RunDialogAtom;
  ClientEvent.Data.l[1] := Round(Frac(Now)*1000);

  // run panel
  XSendEvent(Display, ClientEvent.Window, false, 
StructureNotifyMask, PXEvent(@ClientEvent)); XCloseDisplay(Display); end.

Save it as gnome_run.pas. Compile it using fpc gnome_run.pas -CX -OG2 -XXs. Run it. Viola, the Run Command dialog popped up in front of me.🙂

run_command.png

 » Program shortcut on Ubuntu’s main menu.

Ok, I think it’s enough playing around with xlib and Gnome. It’s time to back to my real job.😀

9 Responses to Gnome’s Run Command Dialog

  1. Meti says:

    poor gnome….

    i just click “cassandra” – “run program” in my MintXFCE kekekekeke…….

  2. Bee says:

    Ubuntu also has the Alt+F2 keyboard shortcut to launch this dialog. But that’s not the point. I want to launch the dialog by point-and-click on a (main-)menu item, using mouse, not using keyboard and the cryptic shortcut.😀

  3. mica says:

    Ahh
    I see.The old (Gnome) problem of removing (useful) options😉

  4. bee says:

    That’s why I said it was a “weird” policy of Gnome. They remove Run Command dialog but still provide console/terminal.😀

  5. steve says:

    fuck pascal, can you post the C source code please?

  6. bee says:

    @steve:
    aha, “nice” word! why don’t you help yourself first then!😛

  7. Andrew says:

    Please indicate what you changed in the code. The only thing I could find was the client event data time information.

  8. Andrew says:

    For those wanting the fix for C, add the following header

    #include

    Then change the second event data assigment to

    event.data.l[1] = (Time)time(NULL);

    HTH

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: