Skip to content

Commit 672fb50

Browse files
authored
Merge pull request #154 from Siborgium/master
Merge enhance-dmenu and bugfixes
2 parents 3adc01e + 430b94c commit 672fb50

File tree

4 files changed

+163
-184
lines changed

4 files changed

+163
-184
lines changed

dmenu/dmenu.cc

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ Insert switch case sensitivity\n";
5757
int main(int argc, char *argv[]) {
5858
std::string custom_css_file {"style.css"};
5959

60-
/* For now the settings file only determines if case_sensitive was turned on.
61-
* Let's just check if the file exists.
62-
**/
60+
// For now the settings file only determines if case_sensitive was turned on.
6361
settings_file = get_settings_path();
64-
if (std::ifstream(settings_file)) {
65-
case_sensitive = false;
62+
if (std::ifstream settings{ settings_file }) {
63+
std::string sensitivity;
64+
settings >> sensitivity;
65+
case_sensitive = sensitivity == "case_sensitive";
6666
}
6767

6868
create_pid_file_or_kill_pid("nwgdmenu");
@@ -188,7 +188,7 @@ int main(int argc, char *argv[]) {
188188
sock.run("for_window [title=\"~nwgdmenu*\"] border none");
189189
}
190190

191-
Gtk::Main kit(argc, argv);
191+
auto app = Gtk::Application::create();
192192

193193
auto provider = Gtk::CssProvider::create();
194194
auto display = Gdk::Display::get_default();
@@ -212,8 +212,8 @@ int main(int argc, char *argv[]) {
212212
// For openbox and similar we'll need the window x, y coordinates
213213
window.show();
214214

215-
DMenu menu;
216-
Anchor anchor(&menu);
215+
DMenu menu{window};
216+
Anchor anchor{menu};
217217
window.anchor = &anchor;
218218

219219
window.signal_button_press_event().connect(sigc::ptr_fun(&on_window_clicked));
@@ -262,30 +262,7 @@ int main(int argc, char *argv[]) {
262262
//~ window.hide();
263263
}
264264

265-
if (show_searchbox) {
266-
auto search_item = new Gtk::MenuItem();
267-
search_item -> add(menu.searchbox);
268-
search_item -> set_name("search_item");
269-
search_item -> set_sensitive(false);
270-
menu.append(*search_item);
271-
}
272-
273-
menu.signal_deactivate().connect(sigc::ptr_fun(Gtk::Main::quit));
274-
275-
int cnt = 0;
276-
for (auto& command : all_commands) {
277-
auto item = new Gtk::MenuItem();
278-
item -> set_label(command);
279-
item -> signal_activate().connect(sigc::bind<std::string>(sigc::ptr_fun(&on_item_clicked),
280-
std::move(command)));
281-
282-
menu.append(*item);
283-
cnt++;
284-
if (cnt > rows - 1) {
285-
break;
286-
}
287-
}
288-
265+
menu.signal_deactivate().connect(sigc::mem_fun(window, &MainWindow::close));
289266
menu.set_reserve_toggle_size(false);
290267
menu.set_property("width_request", w / 8);
291268

@@ -318,7 +295,5 @@ int main(int argc, char *argv[]) {
318295

319296
menu.show_all();
320297

321-
Gtk::Main::run(window);
322-
323-
return 0;
298+
return app->run(window);
324299
}

dmenu/dmenu.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,38 @@ extern bool case_sensitive;
4242

4343
class DMenu : public Gtk::Menu {
4444
public:
45-
DMenu();
46-
Gtk::SearchEntry searchbox;
47-
Glib::ustring search_phrase;
48-
45+
DMenu(Gtk::Window&);
46+
~DMenu();
47+
void emplace_back(const Glib::ustring&);
48+
void show_all() {
49+
Gtk::Menu::show_all();
50+
// required to have first item selected on launch
51+
fix_selection();
52+
}
53+
4954
private:
55+
Gtk::SearchEntry searchbox;
56+
// parent window
57+
Gtk::Window& main;
58+
// the first item in list
59+
Gtk::MenuItem* first_item = nullptr;
60+
// whether case sensitivity was changed during run
61+
bool case_sensitivity_changed = false;
62+
5063
bool on_key_press_event(GdkEventKey* event) override;
5164
void filter_view();
65+
void switch_case_sensitivity();
66+
void fix_selection();
5267
void on_item_clicked(Glib::ustring cmd);
5368
};
5469

5570
class Anchor : public Gtk::Button {
5671
public:
57-
Anchor(DMenu *);
58-
72+
Anchor(DMenu&);
5973
private:
6074
bool on_focus_in_event(GdkEventFocus* focus_event) override;
61-
DMenu *menu;
75+
Gdk::Gravity gravity_widget, gravity_menu;
76+
DMenu& menu;
6277
};
6378

6479
class MainWindow : public CommonWindow {

0 commit comments

Comments
 (0)