alsa-utils/alsamixer/proc_files.c
braph ba1c5357a1 alsamixer: added mouse support
Mouse support has been added for mixer_widget.c, card_select.c and
proc_files.c.

In the mixer widget the mouse is handled as follows:
- After an element has been printed in mixer_display.c, a call to
  clickable_set() will store the coordinates of the drawn area plus the
  command enum that should be executed on click. An optional argument
  holds an index which points to the selected mixer control.
- on_mouse_click() searches for a matching rectangle, focuses the mixer
  control and returns the command enum.

In the menu widgets, the menu_driver() function handles mouse input.

Signed-off-by: Benjamin Abendroth <braph93@gmx.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-07-01 16:10:35 +02:00

141 lines
3.2 KiB
C

/*
* proc_files.c - shows ALSA system information files
* Copyright (c) Clemens Ladisch <clemens@ladisch.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "aconfig.h"
#include <assert.h>
#include <menu.h>
#include <unistd.h>
#include "gettext_curses.h"
#include "utils.h"
#include "die.h"
#include "mem.h"
#include "colors.h"
#include "widget.h"
#include "textbox.h"
#include "proc_files.h"
#include "menu_widget.h"
static struct widget proc_widget;
static ITEM *items[7];
static unsigned int items_count;
static MENU *menu;
static void on_handle_key(int key)
{
ITEM *item;
switch (menu_widget_handle_key(menu, key)) {
case KEY_ENTER:
item = current_item(menu);
if (item)
show_textfile(item_name(item));
break;
case KEY_CANCEL:
proc_widget.close();
break;
}
}
static bool create(void)
{
int rows, columns;
const char *title;
if (screen_lines < 3 || screen_cols < 20) {
proc_widget.close();
beep();
return FALSE;
}
scale_menu(menu, &rows, &columns);
rows += 2;
columns += 2;
if (rows > screen_lines)
rows = screen_lines;
if (columns > screen_cols)
columns = screen_cols;
widget_init(&proc_widget, rows, columns, SCREEN_CENTER, SCREEN_CENTER,
attr_menu, WIDGET_BORDER | WIDGET_SUBWINDOW);
title = _("Select File");
mvwprintw(proc_widget.window, 0, (columns - 2 - get_mbs_width(title)) / 2, " %s ", title);
set_menu_win(menu, proc_widget.window);
set_menu_sub(menu, proc_widget.subwindow);
return TRUE;
}
static void on_window_size_changed(void)
{
unpost_menu(menu);
if (!create())
return;
post_menu(menu);
}
static void on_close(void)
{
unsigned int i;
unpost_menu(menu);
free_menu(menu);
for (i = 0; i < items_count; ++i)
free_item(items[i]);
widget_free(&proc_widget);
}
static void add_item(const char *file_name)
{
if (access(file_name, F_OK) == 0) {
items[items_count] = new_item(file_name, NULL);
if (!items[items_count])
fatal_error("cannot create menu item");
++items_count;
assert(items_count < ARRAY_SIZE(items));
}
}
static struct widget proc_widget = {
.handle_key = on_handle_key,
.window_size_changed = on_window_size_changed,
.close = on_close,
};
void create_proc_files_list(void)
{
items_count = 0;
add_item("/proc/asound/version");
add_item("/proc/asound/cards");
add_item("/proc/asound/devices");
add_item("/proc/asound/oss/devices");
add_item("/proc/asound/timers");
add_item("/proc/asound/pcm");
items[items_count] = NULL;
menu = new_menu(items);
if (!menu)
fatal_error("cannot create menu");
set_menu_fore(menu, attr_menu_selected);
set_menu_back(menu, attr_menu);
set_menu_mark(menu, NULL);
menu_opts_off(menu, O_SHOWDESC);
if (!create())
return;
post_menu(menu);
}